list prerequisite software in README
[challenge-bot] / arduino-sketches / phase0 / phase0.ino
CommitLineData
a77b88c5 1/*
f29767e8 2 This program is free software: you can redistribute it and/or modify
a77b88c5 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 */
1c7c3a52 15
16/*
17 * traffic lights
18 */
19
a77b88c5 20int red0 = 12;
21int yellow0 = 11;
22int green0 = 10;
23
24int red1 = 7;
25int yellow1 = 6;
26int green1 = 5;
27
28void setup() {
a77b88c5 29 pinMode(red0, OUTPUT);
30 pinMode(red1, OUTPUT);
31 pinMode(yellow0, OUTPUT);
32 pinMode(yellow1, OUTPUT);
33 pinMode(green0, OUTPUT);
34 pinMode(green1, OUTPUT);
35}
36
c8ce6466 37/*
38 on(pinNumber);
39 turn on pin 'pinNumber'.
40 digitalWrite(pinNumber, HIGH); turns the voltage on for that pin.
41 */
42void on(int pinToTurnOn) {
43 digitalWrite(pinToTurnOn, HIGH);
a77b88c5 44}
45
c8ce6466 46/*
47 off(pinNumber);
48 turn off pin 'pinNumber'.
49 digitalWrite(pinNumber, LOW); turns the voltage off for that pin.
50*/
51void off(int pinToTurnOff) {
52 digitalWrite(pinToTurnOff, LOW);
a77b88c5 53}
54
c8ce6466 55void onsOffs(int* pinsToTurnOn, int numberOfPinsToTurnOn,
1c7c3a52 56 int* pinsToTurnOff, int numberOfPinsToTurnOff){
c8ce6466 57 // generic index used for arrays of pins to turn on or off
58 int index;
59 // turn off pins in pinsToTurnOff
60 for(index = 0; index < numberOfPinsToTurnOff; index++) {
61 off(pinsToTurnOff[index]);
a77b88c5 62 }
c8ce6466 63 // turn on pins in pinsToTurnOn
64 for(index = 0; index < numberOfPinsToTurnOn; index++) {
65 on(pinsToTurnOn[index]);
a77b88c5 66 }
a77b88c5 67}
68
69void loop() {
c8ce6466 70 int redWait = 300;
71 int yellowWait = 800;
72 int greenWait = 1600;
a77b88c5 73
c8ce6466 74 onsOffs((int[]){red0, green1}, 2,
75 (int[]){yellow0, green0, red1, yellow1}, 4);
76 delay(greenWait);
a77b88c5 77
c8ce6466 78 onsOffs((int[]){red0, yellow1}, 2,
79 (int[]){yellow0, green0, red1, green1}, 4);
80 delay(yellowWait);
a77b88c5 81
c8ce6466 82 onsOffs((int[]){red0, red1}, 2,
83 (int[]){yellow0, green0, yellow1, green1}, 4);
84 delay(redWait);
a77b88c5 85
c8ce6466 86 onsOffs((int[]){green0, red1}, 2,
87 (int[]){red0, yellow0, yellow1, green1}, 4);
88 delay(greenWait);
a77b88c5 89
c8ce6466 90 onsOffs((int[]){yellow0, red1}, 2,
91 (int[]){red0, green0, yellow1, green1}, 4);
92 delay(yellowWait);
a77b88c5 93
c8ce6466 94 onsOffs((int[]){red0, red1}, 2,
95 (int[]){yellow0, green0, yellow1, green1}, 4);
96 delay(redWait);
a77b88c5 97}