blob: 87f07bcf4347d8d8808b47846868589afabf750f (
plain)
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
|
#define AIN1 0
#define AIN2 1
int i = 0;
int down0 = 0;
int down1 = 0;
int color = 0;
int rate = 250;
void setup() {
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
analogReadResolution(8);
}
void set_color() {
if (i % (2 * rate) < rate) digitalWrite(AIN1, LOW), digitalWrite(AIN2, LOW);
else {
if (color) digitalWrite(AIN1, HIGH), digitalWrite(AIN2, LOW);
else digitalWrite(AIN1, LOW), digitalWrite(AIN2, HIGH);
}
}
void loop() {
if (i % rate == 0) set_color(); // Toggle color
// Make sure this is a press and the button isn't already down
if (analogRead(A0) > 200) {
if (!down0) color = !color, set_color();
down0 = 1;
}
else down0 = 0;
if (analogRead(A1) > 200) {
if (!down1) rate = (rate == 250 ? 500 : 250), set_color();
down1 = 1;
}
else down1 = 0;
delay(1);
i++;
}
|