Random timing output
JSGrewal
Posts: 9
First off, thanks for all the great topics in this forum. Because of this place, its been fairly easy for one of my first programming electronic projects in a long long time!
So I am using a BS2 to make a controller for a large humidor. I have been able to get the LCD display and temp/ humidity control to work great. What I want to do is randomly turn on a fan every hour or two for a few minutes. I know I can use an RTC and track time that way, but I dont want to if I can avoid it. The time is not all that critical as long as it turns on every once in a while and runs for a while.
Any suggestions?
So I am using a BS2 to make a controller for a large humidor. I have been able to get the LCD display and temp/ humidity control to work great. What I want to do is randomly turn on a fan every hour or two for a few minutes. I know I can use an RTC and track time that way, but I dont want to if I can avoid it. The time is not all that critical as long as it turns on every once in a while and runs for a while.
Any suggestions?
Comments
If the counter is zero, generate a random number
--- If the state variable is zero, adjust the range of the random number and save it in the counter
--- Turn on the fan
--- Set the state variable to 1
--- If the state variable is 1, adjust the range of the random number and save it in the counter
--- Turn off the fan
--- Set the state variable to 0
If the counter is not zero, decrease it by one
The adjustment of the random number depends on whether you have state 0 or 1 and the random
number becomes the number of times your program goes through its main loop for the time needed
for on or off. The minimum time is the base value, the difference between maximum and minimum
becomes a scale factor for the random number. In other words, you take the random number, multiply
by the scale factor and add the base value. The result is the number of times you go through your main
loop before you change state. The actual numbers depend on the amount of time it takes to go through
the main loop and how long you want the fan on or off.