Hi All
So I am progressing through my home night time subdued lighting project and have recently installed a 12V analogue RGB LED strip on the stairway, activated by an appropriately positioned PIR, and all works fine.
I have a simple setting for the LED's which when the PIR detects a presence, they display a nice purple colour that fades in and out gently - by using two simple 'for' loops, until no presence is detected and they then turn off. What I want to do is something else though, and it's here I need some help and guidance.
Upon detection by the PIR, I want to be able to:
1 - slowly fade in the LED's
2 - have them remain on at that level for the set time as defined by the position of the potentiometer on the PIR sensor module
3 - At the end of the cycle have them gently fade out
Here's my problem, I am not sure how to get them to do this using the structure I have, as the control code is in the 'Void Loop' statement and thus continuously cycles through this loop. I could write the code to achieve what is in 1,2 and 3 above, but then this will continually cycle through fading in, remaining at a level then fading out - all in the cycle to be repeated at whatever speed the Arduino is opetating at etc. and this is not what I want.
So I am trying to figure out a way to have that effect and I am guessing it needs to be done on state change? Would that be the way to do this?
The PIR sensors have two onboard potentiomenters that control the time the detection is kept on, and the sensitivity of the sensor (how far away it will detect someone). The operation is such that upon detection the output is made high, and remains high until 'n' seconds (via onboard potentiometer) after last detection, then goes low, remains low for at least 3 seconds (part of the PIR sensor, don't know why this is the case) and then remains low until movement is detected et al.
So, do I need to learn about state changes so that I can construct some code that will only execute when the state of the PIR output changes etc rather than using the if then else statement I currently have, or is there another alternative, a better way I am not aware of?
Here's the current code I use to control the LED's
// Code for LED Strip control
if (PIRstairsValue == 0)
{
Driver.begin();
Driver.SetColor(0, 0, 0); // Make sure LED's are OFF
Driver.end();
}
else
{
for (i = 50; i < 100; i++) // Simple loop to fade brightness of colour (i) up
{
Driver.begin();
Driver.SetColor(i, 0, i); // Set colour value R-G-B (in this case it is Purple)
Driver.end();
delay(LEDdelay);
}
for (i = 100; i > 50; i--) // Simple loop to fade brighness of colour (i) down
{
Driver.begin();
Driver.SetColor(i, 0, i);
Driver.end();
delay(LEDdelay);
}
}
// End of LED Strip Control code
Any pointers would be appreciated, thanks.