I'm working on a project to make some automatic blinds. They will open and close automatically as it gets light and dark, and also have 2 buttons for manual positioning.
My code works by the buttons changing a variable from 0 to 1 or 2. Depending on wether the variable is 1 or 2 the motor control statement drives the motor in the direction required, or stops it if the variable is 0. I then have a counter which is changed by the values from a rotary encoder. When the counter reaches the set limits in either direction (up or down) it sets the variable to 0.
I have working code for the buttons on their own, and I can get them to open and close with just the light sensor, but not both. I can't work out how to make the light sensor trigger it to close only the first time it detects it's over the light threshold, or below it. At night, when I press the button it opens and then closes again as the light sensor is constantly trying to close them. The opposite during the day.
I have tried making variables for whether it's light or dark and and set it up like a button, referencing its old state etc, but with no joy. I'm pretty new to this and it's probably something simple I'm missing or not using!
Thanks for reading this over, any help would be greatly appreciated!