Hi all,
Easy one but I have been looking at it too long and it has fried my head.
Have an LED set up on on/off timings using millis. But when the LED is in it's 'on' timing state i need it to be controlled by an ambient light sensor, so it could potentially be off even though it is in the 'on' timing section. then the ambient light sensor needs to have no effect on light state when in 'off' state mode.
here is where i am at
const unsigned int onTime = 5000;
const unsigned int offTime = 25000;
unsigned long previousMillis=0;
int interval = onTime;
boolean LED13state = true;
int temt6000Pin = A0;
float light;
int light_value;
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
int light_value = analogRead(temt6000Pin);
int switch_value = digitalRead(10);
light = light_value * 0.0976;
Serial.println(light);
digitalWrite(13, LED13state);
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval && light_value > 1000) {
if (LED13state) {
interval = offTime;
} else {
interval = onTime;
}
LED13state = !(LED13state);
previousMillis = currentMillis;
}
}
LED stays on/off for desired times, i just need to be able to control the brightness using ambient light sensor/photoresistor when it is on.
Thanks in advance.