add code for phase0 through phase3
[challenge-bot] / phase0 / phase0.ino
diff --git a/phase0/phase0.ino b/phase0/phase0.ino
new file mode 100644 (file)
index 0000000..8a80269
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of
+    the License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+  Blink
+  Turns on an LED on for one second, then off for one second, repeatedly.
+
+  This example code is in the public domain.
+ */
+int red0 = 12;
+int yellow0 = 11;
+int green0 = 10;
+
+int red1 = 7;
+int yellow1 = 6;
+int green1 = 5;
+
+void setup() {
+  // initialize the digital pin as an output.
+  // Pin 13 has an LED connected on most Arduino boards:
+
+  pinMode(red0, OUTPUT);
+  pinMode(red1, OUTPUT);
+  pinMode(yellow0, OUTPUT);
+  pinMode(yellow1, OUTPUT);
+  pinMode(green0, OUTPUT);
+  pinMode(green1, OUTPUT);
+}
+
+void on(int led) {
+  digitalWrite(led, HIGH);
+}
+
+void off(int led) {
+  digitalWrite(led, LOW);
+}
+
+void ons_offs(int* ons, int onsc,
+              int* offs, int offsc,
+              int delay_time) {
+  int ii;
+  for(ii = 0; ii < offsc; ii++) {
+    off(offs[ii]);
+  }
+  for(ii = 0; ii < onsc; ii++) {
+    on(ons[ii]);
+  }
+  delay(delay_time);
+}
+
+void loop() {
+  int red_wait = 300;
+  int yellow_wait = 800;
+  int green_wait = 1600;
+
+  ons_offs((int[]){red0, green1}, 2,
+           (int[]){yellow0, green0, red1, yellow1}, 4,
+           green_wait);
+
+  ons_offs((int[]){red0, yellow1}, 2,
+           (int[]){yellow0, green0, red1, green1}, 4,
+           yellow_wait);
+
+  ons_offs((int[]){red0, red1}, 2,
+           (int[]){yellow0, green0, yellow1, green1}, 4,
+           red_wait);
+
+  ons_offs((int[]){green0, red1}, 2,
+           (int[]){red0, yellow0, yellow1, green1}, 4,
+           green_wait);
+
+  ons_offs((int[]){yellow0, red1}, 2,
+           (int[]){red0, green0, yellow1, green1}, 4,
+           yellow_wait);
+
+  ons_offs((int[]){red0, red1}, 2,
+           (int[]){yellow0, green0, yellow1, green1}, 4,
+           red_wait);
+}