Concept
I have inputed both an analog and digital switch to control two LEDs to the same bread board and using the same code. i wanted the digital switch to have a pattern with the red LED and that worked! i also wanted the light detector to turn on when it was dark and I was able to do that! IT was definitely a challenge working with the light detector since i had to rewrite my code a couple of times.
My code
int buttonState = digitalRead(pushButton); if (buttonState == HIGH) { digitalWrite(redLEDPin, HIGH); delay(20); digitalWrite(redLEDPin, LOW); delay(300); digitalWrite(redLEDPin, HIGH); delay(20); digitalWrite(redLEDPin, LOW); delay(300); digitalWrite(redLEDPin, HIGH); delay(700); } allOff(); delay(1000); analogValue = analogRead(LIGHT_SENSOR_PIN); // read the input on analog pin if(analogValue < ANALOG_THRESHOLD) digitalWrite(greenLEDPin, HIGH); // turn on LED else digitalWrite(greenLEDPin, LOW); }
This is the main part of my code that controls both LEDs functions.
I tried to draw a circuit, Its not perfect but i enjoyed it
Arduino
Improvement
I would like to be able to use the analog switch better since I believe that I am not that a-custom to it yet. I also really want to tidy my breadboard for it to be more organized since I got lost with the wires sometimes