So the code I already pasted here it’s almost perfect but it just needs the part on what happens when you leave the door open.
Yes, it’s a room occupancy indicator with a sliding door, so when the door is open the distance to the sensor is < 30, when door is closed distance is > 30.
This is what happens with my actual code I pasted first:
RGB led is greed by default (in setup).
When you open the door, ab close it back in less than few seconds, the LED toggles from green to red to show that the room is busy.
When you open and close the door again, the LED toggles again and will become green again to show that the room is free.
But when you leave the door open for more than 5 seconds, now the LED switches from green to red, with the 5 sec. delay time set in the LED toggle section. And instead of auto-toggleing every 5 seconds I want it to stay green after 5 seconds, if the door is left open so you know it’s free. That’s all.
And then, after you close it, shoud go back to the toggleing code when you open and close the door, starting with color red (so you know the room it’s busy after you close the door).
This part of code should not be eliminated because it switches from green to red and viceversa when you get in and out the room (open and close the door in less than 5 seconds):
if (distance < 30) {
analogWrite(red_LED, toggle * 255);
analogWrite(red_LED_int, toggle * 30);
if (toggle == 1) toggle = 0; else toggle = 1;
analogWrite(green_LED, toggle * 25);
analogWrite(green_LED_int, toggle * 10);
delay (5000);
}