#include <Servo.h>
Servo myservoA;
Servo myservoB;
Servo myservoC;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define Sensor 2
#define LEDA 3
#define LEDB 4
#define Buzz 5
#define coinDetector 6
#define SWA A3
#define SWB A2
#define SWC A1
int servostop = 90;
int servoplay = 180;
int coinCount = 10;
int buttonPressed;
void setup() {
lcd.init();
lcd.begin(16, 2);
lcd.backlight();
lcd.print(" Hello ");
lcd.setCursor(0, 1);
delay(2000);
lcd.clear();
lcd.print(" insert a coin ");
lcd.setCursor(0, 1);
delay(2000);
pinMode(Sensor, INPUT);
pinMode(LEDA, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(Buzz, OUTPUT);
pinMode(coinDetector, INPUT_PULLUP);
pinMode(SWA, INPUT_PULLUP);
pinMode(SWB, INPUT_PULLUP);
pinMode(SWC, INPUT_PULLUP);
myservoA.attach(7);
myservoB.attach(8);
myservoC.attach(9);
myservoA.write(servostop);
myservoB.write(servostop);
myservoC.write(servostop);
BuzzC();
digitalWrite(LEDB, LOW);
}
void loop() {
digitalWrite(LEDA, HIGH);
while (true) {
if (digitalRead(coinDetector) == LOW) {
delay(50);
lcd.clear();
lcd.print("Coins: ");
lcd.print(coinCount);
lcd.print(" Bath ");
delay(2000);
break;
}
}
BuzzB();
digitalWrite(LEDA, LOW);
delay(200);
digitalWrite(LEDA, HIGH);
delay(200);
digitalWrite(LEDA, LOW);
delay(200);
digitalWrite(LEDA, HIGH);
delay(200);
digitalWrite(LEDA, LOW);
delay(200);
digitalWrite(LEDA, HIGH);
while (true) {
if (digitalRead(SWA) == LOW) {
lcd.clear();
lcd.print(" lOADING......1 ");
lcd.print(servoplay);
delay(2000);
buttonPressed = 1;
BuzzA();
digitalWrite(LEDA, LOW);
digitalWrite(LEDB, HIGH);
break;
}
if (digitalRead(SWB) == LOW) {
lcd.clear();
lcd.print(" lOADING......2 ");
lcd.print(servoplay);
delay(2000);
buttonPressed = 2;
BuzzA();
digitalWrite(LEDA, LOW);
digitalWrite(LEDB, HIGH);
break;
}
if (digitalRead(SWC) == LOW) {
lcd.clear();
lcd.print(" lOADING......3 ");
lcd.print(servoplay);
delay(2000);
buttonPressed = 3;
BuzzA();
digitalWrite(LEDA, LOW);
digitalWrite(LEDB, HIGH);
break;
}
}
switch (buttonPressed) {
case 1:
myservoA.write(servoplay);
break;
case 2:
myservoB.write(servoplay);
break;
case 3:
myservoC.write(servoplay);
break;
}
while (true) {
if (digitalRead(Sensor) == LOW) {
myservoA.write(servostop);
myservoB.write(servostop);
myservoC.write(servostop);
BuzzC();
break;
}
}
while (true) {
if (digitalRead(Sensor) == HIGH) {
lcd.clear();
lcd.print(" Please pick up ");
lcd.print(Sensor);
delay(10000);
lcd.clear();
lcd.print(" THANK YOU ");
lcd.print(Sensor);
delay(5000);
lcd.clear();
lcd.print(" Hello ");
digitalWrite(LEDB, LOW);
break;
}
}
}
void BuzzA()
{
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
}
void BuzzB()
{
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(50);
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
}
void BuzzC()
{
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(50);
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(50);
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
}