diff options
author | Anthony Wang | 2022-09-22 15:25:34 -0400 |
---|---|---|
committer | Anthony Wang | 2022-09-22 15:25:34 -0400 |
commit | d78c18b6a3214f43635863a0c49bb35413d83306 (patch) | |
tree | 3f3b857a295cbf0e2ae951348ca87c1b6231532f |
Initial commit
-rw-r--r-- | libraries/readme.txt | 1 | ||||
-rw-r--r-- | week2/main.ino | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/libraries/readme.txt b/libraries/readme.txt new file mode 100644 index 0000000..96ce674 --- /dev/null +++ b/libraries/readme.txt @@ -0,0 +1 @@ +For information on installing libraries, see: http://www.arduino.cc/en/Guide/Libraries diff --git a/week2/main.ino b/week2/main.ino new file mode 100644 index 0000000..87f07bc --- /dev/null +++ b/week2/main.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++; +} |