Hi All,
New here with a question:
I'd like to add an override code to the program below. Using a momentary pushbutton, I'd like the override the code to turn the light on and hold until the button is pressed again, at which point it will go on to its regular programming.
I've done a lot of searching on this forum and on the web, but can't find a code. Most searches for "override code" result in some internal function to the Uno (board I'm using).
Can anyone point me in the right direction or help with writing the code?
Sorry if it's a totally newbie question, but been stuck at it for days.
Thanks!
Dweep
==============================
/* Photocell simple testing sketch.
Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
For more information see www.ladyada.net/learn/sensors/cds.html */
int photocellPin = 4; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading
// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
Serial.println(" - Dim");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
}
//This code turns light on and off based on sensor reading
if (photocellReading < 200) {
digitalWrite(2, HIGH);
} else if (photocellReading > 400) {
digitalWrite(2, LOW);
}
delay(1000);
}