#include <Servo.h>
Servo myservoA;
Servo myservoB;
Servo myservoC;
#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 = 0;
int servoplay = 10;
int buttonPressed;
void setup() {
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) {
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) {
buttonPressed = 1;
BuzzA();
digitalWrite(LEDA, LOW);
digitalWrite(LEDB, HIGH);
break;
}
if (digitalRead(SWB) == LOW) {
buttonPressed = 2;
BuzzA();
digitalWrite(LEDA, LOW);
digitalWrite(LEDB, HIGH);
break;
}
if (digitalRead(SWC) == LOW) {
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) {
delay(1000);
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);
}