From 4c588943fc8c29b74664f23e9305fcfa5e16e200 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 22 Sep 2022 16:35:59 -0400 Subject: Finish week3 simple simon code --- week2/main.ino | 41 ----------------------------------------- week2/week2.ino | 41 +++++++++++++++++++++++++++++++++++++++++ week3/week3.ino | 21 +++++++++++++++++++++ 3 files changed, 62 insertions(+), 41 deletions(-) delete mode 100644 week2/main.ino create mode 100644 week2/week2.ino create mode 100644 week3/week3.ino diff --git a/week2/main.ino b/week2/main.ino deleted file mode 100644 index 87f07bc..0000000 --- a/week2/main.ino +++ /dev/null @@ -1,41 +0,0 @@ -#define AIN1 0 -#define AIN2 1 - -int i = 0; -int down0 = 0; -int down1 = 0; -int color = 0; -int rate = 250; - -void setup() { - pinMode(AIN1, OUTPUT); - pinMode(AIN2, OUTPUT); - analogReadResolution(8); -} - -void set_color() { - if (i % (2 * rate) < rate) digitalWrite(AIN1, LOW), digitalWrite(AIN2, LOW); - else { - if (color) digitalWrite(AIN1, HIGH), digitalWrite(AIN2, LOW); - else digitalWrite(AIN1, LOW), digitalWrite(AIN2, HIGH); - } -} - -void loop() { - if (i % rate == 0) set_color(); // Toggle color - - // Make sure this is a press and the button isn't already down - if (analogRead(A0) > 200) { - if (!down0) color = !color, set_color(); - down0 = 1; - } - else down0 = 0; - if (analogRead(A1) > 200) { - if (!down1) rate = (rate == 250 ? 500 : 250), set_color(); - down1 = 1; - } - else down1 = 0; - - delay(1); - i++; -} diff --git a/week2/week2.ino b/week2/week2.ino new file mode 100644 index 0000000..87f07bc --- /dev/null +++ b/week2/week2.ino @@ -0,0 +1,41 @@ +#define AIN1 0 +#define AIN2 1 + +int i = 0; +int down0 = 0; +int down1 = 0; +int color = 0; +int rate = 250; + +void setup() { + pinMode(AIN1, OUTPUT); + pinMode(AIN2, OUTPUT); + analogReadResolution(8); +} + +void set_color() { + if (i % (2 * rate) < rate) digitalWrite(AIN1, LOW), digitalWrite(AIN2, LOW); + else { + if (color) digitalWrite(AIN1, HIGH), digitalWrite(AIN2, LOW); + else digitalWrite(AIN1, LOW), digitalWrite(AIN2, HIGH); + } +} + +void loop() { + if (i % rate == 0) set_color(); // Toggle color + + // Make sure this is a press and the button isn't already down + if (analogRead(A0) > 200) { + if (!down0) color = !color, set_color(); + down0 = 1; + } + else down0 = 0; + if (analogRead(A1) > 200) { + if (!down1) rate = (rate == 250 ? 500 : 250), set_color(); + down1 = 1; + } + else down1 = 0; + + delay(1); + i++; +} diff --git a/week3/week3.ino b/week3/week3.ino new file mode 100644 index 0000000..4051901 --- /dev/null +++ b/week3/week3.ino @@ -0,0 +1,21 @@ +void setup() { + pinMode(0, OUTPUT); + pinMode(1, OUTPUT); + analogReadResolution(8); +} + +void loop() { + int light = random(0, 2); + delay(1000); + digitalWrite(light, HIGH); + delay(1000); + digitalWrite(light, LOW); + while (analogRead(A0) < 240 && analogRead(A1) < 240); + int correct = (analogRead(A0) < 128) ^ light; + for (int i = 0; i < 4; ++i) { + digitalWrite(correct, HIGH); + delay(200); + digitalWrite(correct, LOW); + delay(200); + } +} -- cgit v1.2.3-70-g09d2