523ca5f5cec8e32dc0b1df41bc1ebb403a7aaf80
[challenge-bot] / phase0 / phase0.ino
1 /*
2 This program is free software: you can redistribute it and/or modify
3 it under the terms of the GNU Affero General Public License as
4 published by the Free Software Foundation, either version 3 of
5 the License, or (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU Affero General Public License for more details.
11
12 You should have received a copy of the GNU Affero General Public License
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15 int red0 = 12;
16 int yellow0 = 11;
17 int green0 = 10;
18
19 int red1 = 7;
20 int yellow1 = 6;
21 int green1 = 5;
22
23 void setup() {
24 pinMode(red0, OUTPUT);
25 pinMode(red1, OUTPUT);
26 pinMode(yellow0, OUTPUT);
27 pinMode(yellow1, OUTPUT);
28 pinMode(green0, OUTPUT);
29 pinMode(green1, OUTPUT);
30 }
31
32 /*
33 on(pinNumber);
34 turn on pin 'pinNumber'.
35 digitalWrite(pinNumber, HIGH); turns the voltage on for that pin.
36 */
37 void on(int pinToTurnOn) {
38 digitalWrite(pinToTurnOn, HIGH);
39 }
40
41 /*
42 off(pinNumber);
43 turn off pin 'pinNumber'.
44 digitalWrite(pinNumber, LOW); turns the voltage off for that pin.
45 */
46 void off(int pinToTurnOff) {
47 digitalWrite(pinToTurnOff, LOW);
48 }
49
50 void onsOffs(int* pinsToTurnOn, int numberOfPinsToTurnOn,
51 int* pinsToTurnOff, int numberOfPinsToTurnOff){
52 // generic index used for arrays of pins to turn on or off
53 int index;
54 // turn off pins in pinsToTurnOff
55 for(index = 0; index < numberOfPinsToTurnOff; index++) {
56 off(pinsToTurnOff[index]);
57 }
58 // turn on pins in pinsToTurnOn
59 for(index = 0; index < numberOfPinsToTurnOn; index++) {
60 on(pinsToTurnOn[index]);
61 }
62 }
63
64 void loop() {
65 int redWait = 300;
66 int yellowWait = 800;
67 int greenWait = 1600;
68
69 onsOffs((int[]){red0, green1}, 2,
70 (int[]){yellow0, green0, red1, yellow1}, 4);
71 delay(greenWait);
72
73 onsOffs((int[]){red0, yellow1}, 2,
74 (int[]){yellow0, green0, red1, green1}, 4);
75 delay(yellowWait);
76
77 onsOffs((int[]){red0, red1}, 2,
78 (int[]){yellow0, green0, yellow1, green1}, 4);
79 delay(redWait);
80
81 onsOffs((int[]){green0, red1}, 2,
82 (int[]){red0, yellow0, yellow1, green1}, 4);
83 delay(greenWait);
84
85 onsOffs((int[]){yellow0, red1}, 2,
86 (int[]){red0, green0, yellow1, green1}, 4);
87 delay(yellowWait);
88
89 onsOffs((int[]){red0, red1}, 2,
90 (int[]){yellow0, green0, yellow1, green1}, 4);
91 delay(redWait);
92 }