Shop OBEX P1 Docs P2 Docs Learn Events
Need some programming help for solar system running on BS2p — Parallax Forums

Need some programming help for solar system running on BS2p

pumpmckpumpmck Posts: 1
edited 2013-01-14 16:51 in BASIC Stamp
1st, I am not sure I am posting this like you would want as I am adding it a previous thread.

Hi
I have a solar system running on BS2p. I am trying to do some fine tuning to save space and I have an If statement that I can't seem to make work the way I want.
The sample code:
INPUT 8 'blue pb led
'DEBUG "S" ' ************************************
DEBUG "in8---",BIN IN8," sp--", BIN sp ' **********Solar Pump ***************
whspon = (~IN8 & ~sp) ' ************************************
whspoff =(IN8 & sp)
DEBUG " whspon--", BIN1 whspon,CR
' DEBUG "whspoff--", BIN1 whspoff,CR

"**********************************************************************************************************************
I apparently am missing something as I can't seem to make these if statements work. CAN YOU HELP?
I have tried many different ways but so far can't seem to make the if statement work when I am trying to do a logical AND on two bit variables.

IF (~IN8=1 & ~sp=1) THEN sp=1:DEBUG "Solar pump turned on" 'water heater turned on
IF (IN8=1 & sp=1) THEN sp=0:DEBUG "Solar pump turned off"

"************************************************************************************************************
" when I use the if statement like this it works like I want, but I am testing the variable that I am setting and I would like to eliminate the extra step
If (whspon=1) then sp=1:DEBUG "Solar pump turned on"
If (whspoff)=1 then sp=0: :DEBUG "Solar pump turned off"

Thanks
Mike

Comments

  • SapphireSapphire Posts: 496
    edited 2013-01-14 16:51
    It might be that you are mixing boolean and logical AND. The "&" character means boolean AND, and can be used in assignment and test. The logical AND operator, literally "AND" is used for comparison only (usually) and not assignment.

    So,
    IF (~IN8=1 & ~sp=1) THEN sp=1:DEBUG "Solar pump turned on" 'water heater turned on
    

    should be
    IF (IN8=0 AND sp=0) THEN sp=1:DEBUG "Solar pump turned on" 'water heater turned on
    

    Also, how is sp defined? If it is a byte, ~sp will give unusual results. Better to test sp=0 than ~sp=1 because ~sp is not 1 when sp is 0, it's 255!
Sign In or Register to comment.