-
Notifications
You must be signed in to change notification settings - Fork 0
/
LedsHunt.ino
58 lines (50 loc) · 1.23 KB
/
LedsHunt.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
int MAX_WIDTH = 3;
int greenLedP = 12;
int redLedP = 10;
int yellowLedP = 8;
int buttonLeft = 2;
int buttonRight = 4;
int ledsP[] = {greenLedP,redLedP,yellowLedP};
int positionLed = 0;
void setup() {
// put your setup code here, to run once:
pinMode(greenLedP,OUTPUT);
pinMode(redLedP,OUTPUT);
pinMode(yellowLedP,OUTPUT);
pinMode(buttonRight, INPUT);
pinMode(buttonLeft, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int actualPin = ledsP[positionLed];
digitalWrite(actualPin,HIGH);
if(digitalRead(buttonRight)==HIGH){
// if(positionLed<MAX_WIDTH){
positionLed = ++positionLed%MAX_WIDTH;
// }
waitTillKeyNotPress(buttonRight);
}
// movePlayer(buttonPin, positionLed, true);
//movePlayer(buttonPin2, positionLed, false);
int previousPin = actualPin;
digitalWrite(previousPin, LOW);
}
void movePlayer(int buttonPin, int positionLed, boolean increases){
if(digitalRead(buttonPin)==HIGH){
if(increases){
if(positionLed<MAX_WIDTH){
positionLed++;
}
}else{
if(positionLed>0){
positionLed--;
}
}
}
waitTillKeyNotPress(buttonPin);
}
void waitTillKeyNotPress(int pin){
while(digitalRead(pin)==HIGH){
delay(10);
}
}