Help with CASE statement
I am trying to build a garden/lawn sprinkler timer. Yes, I know, probably cheaper and easier to just buy one.... After some trial and error, I simplified the idea to "let just make an alarm clock" (same idea, set the DS1302 real time clock, set a time to do something, stay on a certain length of time, turn off, etc) And, I will also admit, this project may never get completed enough to water the lawn, but everyone has to start with an idea and a problem to work to find a solution to! Ha ha!
I am using my original Propeller Professional Development Board with a Parallax 4x20 LCD hooked up to one of the servo headers, and using 4 of the buttons at the bottom of the PPDB as inputs. Currently I am using one of the LEDs on the board as my output (alarm clock on, zone on, etc.)
Ok, so back to the subject. I have a repeat loop in my MAIN object. At the end of the loop I have a CASE statement with four options (set zone/alarm time, set DS1302 time, all zones off, and run). It looks something like:
inKey := %1111 'Initialize inKey variable
inKey := INA[PushButton3..PushButton0] 'Get number (in binary).
if inKey <> PushButtonMask case inKey %0111: SetTimer 'Go to SetZone method %1011: SetTime 'Go to SetTime method %1101: AllZoneStop 'Go to AllZoneStop method
' %1110: Active := True 'Set Active variable to TRUE
' %1110: Run2 'Go to Run2 method, to set Active to TRUE
%1110: Active := 1 'Set Active variable to 1 (TRUE), 0=FALSE
My original plan was to use the variable ACTIVE as a flag, push the RUN button, ACTIVE gets set to TRUE and somewhere else in the code looks at Active and determines if the alarm clock is turned on or off. Later, if I wanted to turn the alarm clock off (or turn the garden timer off), I could set ACTIVE to FALSE, etc. The Active := True statement never seemed to work.
Elsewhere in the code I have:
If Active == True
....(turn on alarm, etc)
After this did not work, I added a few lines in my code to show the value of Active, I could see it never seemed to get set to TRUE. Here is that section of my code:
If Active == TRUE
elseif Active == FALSE
And, after I could not get a response from viewing TRUE/FALSE, I added "Q" just to see if I could pull something/anything from what the variable was equal to.
Then, I though maybe I need to send this to a separate method, like the other CASE options, hence the "Run2", with basically the same Active := True statement. Again, this did not work.
Finally I just set Active := 1 when the button is pressed, and Active := 0 to turn the alarm off, and it worked.
I know, I know, trial and error if you ever saw it....
Having said all that, I am left with the simple question, why did my original thought of setting a flag to TRUE or FALSE not work?
If anyone has any input, I would appreciate it. Thank you in advance.