/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: "Buzzer Relay"
- Source Code NOT compiled for: Arduino Nano ESP32
- Source Code created on: 2024-06-14 16:51:43
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* This code will program an arduino nano to */
/* communicate and operate my cube hopper mk2 via */
/* rs232 so that when an icp pa7 bill acceptor take */
/* a dollor it gives out 4 quarters every time a */
/* dollar is accepted turn on buzzer for 500ms */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // https://github.com/ArduinoGetStarted/buzzer
#include // https://github.com/rafaelnsantos/Relay
#include // For RS232 communication
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void checkBillAcceptor(void);
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t buzz1_PassiveBuzzer_Signal_PIN_D2 = 2;
const uint8_t myRelayModule_RelayModule_Signal_PIN_D3 = 3;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool buzz1_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
bool myRelayModule_RelayModule_Signal_PIN_D3_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float buzz1_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;
float myRelayModule_RelayModule_Signal_PIN_D3_phyData = 0.0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
ezBuzzer buzzer(buzz1_PassiveBuzzer_Signal_PIN_D2); // Initialize ezBuzzer object with the pin
Relay myRelay(myRelayModule_RelayModule_Signal_PIN_D3, true); // Initialize Relay object with the pin and Normally Open configuration
void setup(void) {
// put your setup code here, to run once:
Serial.begin(9600); // Initialize RS232 communication
pinMode(buzz1_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
myRelay.begin(); // Initialize the relay pin
}
void loop(void) {
// put your main code here, to run repeatedly:
buzzer.loop(); // Call the buzzer.loop() function in loop()
checkBillAcceptor(); // Check if a dollar is accepted
updateOutputs(); // Refresh output data
}
void updateOutputs() {
digitalWrite(buzz1_PassiveBuzzer_Signal_PIN_D2, buzz1_PassiveBuzzer_Signal_PIN_D2_rawData);
if (myRelayModule_RelayModule_Signal_PIN_D3_rawData) {
myRelay.turnOn(); // Turn relay on
} else {
myRelay.turnOff(); // Turn relay off
}
}
void checkBillAcceptor() {
if (Serial.available() > 0) {
int receivedByte = Serial.read();
// Assuming the bill acceptor sends a specific byte when a dollar is accepted
if (receivedByte == 'D') { // Replace 'D' with the actual byte sent by the bill acceptor
// Dollar accepted
buzzer.beep(500); // Turn on buzzer for 500ms
for (int i = 0; i < 4; i++) {
myRelay.turnOn(); // Turn relay on to dispense a quarter
delay(250); // Adjust delay as needed for the dispensing mechanism
myRelay.turnOff(); // Turn relay off
delay(250); // Adjust delay as needed for the dispensing mechanism
}
}
}
}
/* END CODE */