summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-09-22 16:56:23 -0400
committerAnthony Wang2022-09-22 16:56:23 -0400
commit7e3cd4f91d5fd1c0d19953e3d0432e6d31cf6cbf (patch)
treebe126906e46385661a96a7218e86fd476e3c754e
parent4c588943fc8c29b74664f23e9305fcfa5e16e200 (diff)
Start working on week4 (using goto!)
-rw-r--r--week4/week4.ino33
1 files changed, 33 insertions, 0 deletions
diff --git a/week4/week4.ino b/week4/week4.ino
new file mode 100644
index 0000000..14acb28
--- /dev/null
+++ b/week4/week4.ino
@@ -0,0 +1,33 @@
+void setup() {
+ for (int i = 0; i < 8; ++i) pinMode(i, OUTPUT);
+ analogReadResolution(8);
+}
+
+void loop() {
+ int len = 0;
+ int seq[1000];
+ while (1) {
+ seq[len++] = random(0, 4);
+ for (int i = 0; i < len; ++i) {
+ digitalWrite(seq[i]<<1|1, HIGH);
+ delay(500);
+ digitalWrite(seq[i]<<1|1, LOW);
+ delay(500);
+ }
+ for (int i = 0; i < len; ++i) {
+ while (analogRead(A0) < 240 && analogRead(A1) < 240 && analogRead(A2) < 240 && analogRead(A3) < 240);
+ for (int j = 0; j < 4; ++j)
+ if (analogRead(A0+j) > 240 && seq[i] != j) goto DONE; // Legit use case of goto to jump out of 2 loops
+ delay(500);
+ }
+ for (int i = 0; i < 8; ++i) {
+ for (int j = 0; j < 4; ++j) digitalWrite(j<<1|1, i&1^1);
+ delay(100);
+ }
+ }
+ DONE:
+ for (int i = 0; i < 8; ++i) {
+ for (int j = 0; j < 4; ++j) digitalWrite(j<<1, i&1^1);
+ delay(100);
+ }
+}