Ok, I have a PIR and some code which work together fine.
At the moment if motion is continuous the LED brightens from 0-255, then jumps back to 0 and climbs to 255 again (as expected) if motion is continuous.
I would like the output (LED) to remain at (255 = brightest) until no motion is detected for x number of subsequent digitalReads of the input.
How to implement this?
Thanks a bunch.
int LED = 11;
int sensor = 7;
int n = 0;
int light = 0;
void setup(){
pinMode(LED, OUTPUT);
pinMode(sensor, INPUT);
digitalWrite(LED, LOW);
Serial.begin(9600);
delay(1000);
}
void loop(){
int sens = digitalRead(sensor);
if(sens == LOW)
{
for(n=0; n<255; n++)
{
analogWrite(LED, n);
delay(10);
Serial.println(n);
}
light = 1;
}
if (light == 1)
{
if (sens == HIGH)
{
for(n=255; n>-1; n--)
{
analogWrite(LED, n);
delay(10);
Serial.println(n);
}
light = 0;
}
}
}