1
2#include <Servo.h>
3byte phres[3]={A0,A1,A2};
4
5int sensorValue = 0;
6int index=0;
7int score = 0;
8
9Servo servo_A3;
10Servo servo_A4;
11Servo servo_A5;
12Servo S[3]={servo_A3,servo_A4,servo_A5};
13
14void setup()
15{
16 pinMode(A0, INPUT);
17 pinMode(A1, INPUT);
18 pinMode(A2, INPUT);
19 servo_A3.attach(A3);
20 servo_A4.attach(A4);
21 servo_A5.attach(A5);
22 pinMode(13, OUTPUT);
23 S[0].write(0);
24 S[1].write(0);
25 S[2].write(0);
26 Serial.begin(9600);
27 randomSeed(analogRead(A3));
28 index = random(0,3);
29 rand_up(index);
30}
31
32void rand_up(int index){
33 S[index].write(90);
34}
35
36void rand_down(int index){
37 S[index].write(0);
38}
39
40void loop()
41{
42 sensorValue = analogRead(phres[index]);
43 if(sensorValue > 150){
44 digitalWrite(13, HIGH);
45 rand_down(index);
46 delay(1000);
47 score = score + 1;
48 Serial.print(score);
49 digitalWrite(13, LOW);
50 index = random(0,3);
51 rand_up(index);
52 }
53
54 delay(1000);
55}
56