Concept
Since we didn’t have enough time in class to go over the analog sensor, I kept my in class activity project using two digital sensors, the buttons, to have different outputs per button and a completely different output for pressing both buttons.
Project
For my circuit, I had two buttons each connected to a resistor and a input slot A2 and A5 where if one of the buttons are pressed, the correlating LED light will blink in an 500 delay interval. If the button is released, then the light will stop blinking. If both of the buttons are pressed, then both lights will blink at 100 delay interval.
Code
void setup() { pinMode(8, OUTPUT); pinMode(12, OUTPUT); pinMode(A2, INPUT); pinMode(A5, INPUT); } void loop() { int switchPosition = digitalRead(A2); int falsePosition = digitalRead(A5); if(switchPosition == LOW && falsePosition == LOW){ digitalWrite(8, LOW); digitalWrite(12, LOW); } else if(switchPosition == HIGH && falsePosition == HIGH){ bothBlink(); } else if (switchPosition == HIGH) { yellowBlink(); } else if(falsePosition == HIGH){ greenBlink(); } } void greenBlink(){ digitalWrite(12, HIGH); delay(blinkDelay); digitalWrite(12, LOW); delay(blinkDelay); } void yellowBlink(){ digitalWrite(8, HIGH); delay(blinkDelay); digitalWrite(8, LOW); delay(blinkDelay); } void bothBlink(){ digitalWrite(8, HIGH); digitalWrite(12, HIGH); delay(100); digitalWrite(8, LOW); digitalWrite(12, LOW); delay(100); }
Video
Future Improvements
Initially I was trying to have the buttons as a trigger to a function that will continue in a loop so that the lights will keep blinking if I pressed the button once and will stop blinking if I pressed it again. However, since I was not so proficient with arduino yet, I failed to achieve the effect. I think this could be an improvement I could work on for future practices.