a77b88c5 |
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 | /* |
16 | Blink |
17 | Turns on an LED on for one second, then off for one second, repeatedly. |
18 | |
19 | This example code is in the public domain. |
20 | */ |
21 | int red0 = 12; |
22 | int yellow0 = 11; |
23 | int green0 = 10; |
24 | |
25 | int red1 = 7; |
26 | int yellow1 = 6; |
27 | int green1 = 5; |
28 | |
29 | void setup() { |
30 | // initialize the digital pin as an output. |
31 | // Pin 13 has an LED connected on most Arduino boards: |
32 | |
33 | pinMode(red0, OUTPUT); |
34 | pinMode(red1, OUTPUT); |
35 | pinMode(yellow0, OUTPUT); |
36 | pinMode(yellow1, OUTPUT); |
37 | pinMode(green0, OUTPUT); |
38 | pinMode(green1, OUTPUT); |
39 | } |
40 | |
41 | void on(int led) { |
42 | digitalWrite(led, HIGH); |
43 | } |
44 | |
45 | void off(int led) { |
46 | digitalWrite(led, LOW); |
47 | } |
48 | |
49 | void ons_offs(int* ons, int onsc, |
50 | int* offs, int offsc, |
51 | int delay_time) { |
52 | int ii; |
53 | for(ii = 0; ii < offsc; ii++) { |
54 | off(offs[ii]); |
55 | } |
56 | for(ii = 0; ii < onsc; ii++) { |
57 | on(ons[ii]); |
58 | } |
59 | delay(delay_time); |
60 | } |
61 | |
62 | void loop() { |
63 | int red_wait = 300; |
64 | int yellow_wait = 800; |
65 | int green_wait = 1600; |
66 | |
67 | ons_offs((int[]){red0, green1}, 2, |
68 | (int[]){yellow0, green0, red1, yellow1}, 4, |
69 | green_wait); |
70 | |
71 | ons_offs((int[]){red0, yellow1}, 2, |
72 | (int[]){yellow0, green0, red1, green1}, 4, |
73 | yellow_wait); |
74 | |
75 | ons_offs((int[]){red0, red1}, 2, |
76 | (int[]){yellow0, green0, yellow1, green1}, 4, |
77 | red_wait); |
78 | |
79 | ons_offs((int[]){green0, red1}, 2, |
80 | (int[]){red0, yellow0, yellow1, green1}, 4, |
81 | green_wait); |
82 | |
83 | ons_offs((int[]){yellow0, red1}, 2, |
84 | (int[]){red0, green0, yellow1, green1}, 4, |
85 | yellow_wait); |
86 | |
87 | ons_offs((int[]){red0, red1}, 2, |
88 | (int[]){yellow0, green0, yellow1, green1}, 4, |
89 | red_wait); |
90 | } |