Help with IR controlled Thermostat
new thermostat.bs2
Hello I am new to the forum and new to programming but I have learned alot along the way. This is my first project meant for a permanent solution so I am really trying to work out all the little bugs. I have a BS2 a 1620 temp sensor a photo cell an IR reciever and a universal remote programmed for the sony protocal. I have wrote some of this code and coppied some from examples i found on the internet. It works pretty well with the exception of one kind of major problem. The main routine will run well untill it sees some IR and then it goes into the temp entry sub routine. It will then check to see what the command from the remote is and apply it to the desired temperature. Problem is if it sees a remote code and it is not a command from the sony protocol it will stay in the temp entry or the get remote code subroutine (not sure which) I guess what i need is to set up a way to verify a sony protocol and if it isn't return to the main routine.
Thanks in advance for any insite on this issue. Sorry the code is kind of scrambled I tried to keep it somewhat clean.
Hello I am new to the forum and new to programming but I have learned alot along the way. This is my first project meant for a permanent solution so I am really trying to work out all the little bugs. I have a BS2 a 1620 temp sensor a photo cell an IR reciever and a universal remote programmed for the sony protocal. I have wrote some of this code and coppied some from examples i found on the internet. It works pretty well with the exception of one kind of major problem. The main routine will run well untill it sees some IR and then it goes into the temp entry sub routine. It will then check to see what the command from the remote is and apply it to the desired temperature. Problem is if it sees a remote code and it is not a command from the sony protocol it will stay in the temp entry or the get remote code subroutine (not sure which) I guess what i need is to set up a way to verify a sony protocol and if it isn't return to the main routine.
Thanks in advance for any insite on this issue. Sorry the code is kind of scrambled I tried to keep it somewhat clean.


Comments
Please post your code and let see what up and maybe we can help you with it
' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ EEPROM Data ]----------------------------------------------------- DATA 72 ' -----[ I/O Definitions ]------------------------------------------------ IrDet PIN 9 ' -----[ Constants ]------------------------------------------------------ ' SONY TV IR remote constants for non-keypad buttons readlight PIN 8 Enter CON 11 ChUp CON 16 ChDn CON 17 VolUp CON 18 VolDn CON 19 Power CON 21 Mute CON 20 Prev CON 59 Menu CON 96 Ext CON 99 Frmat CON 61 auto CON 1 alwayson CON 0 defchr0 CON 248 defchr1 CON 249 defchr2 CON 250 defchr3 CON 251 defchr4 CON 252 defchr5 CON 253 defchr6 CON 254 defchr7 CON 255 lcdpin CON 0 Baud CON 32 LcdBLon CON $11 LcdBLoff CON $12 LcdCls CON $0C ' clear LCD (use PAUSE 5 after) Lcdon CON 22 L013 CON 141 L016 CON 144 L017 CON 145 L018 CON 146 L113 CON 161 L114 CON 162 L116 CON 164 L117 CON 165 L118 CON 166 L207 CON 175 L216 CON 184 ' -----[ Variables ]------------------------------------------------------ irPulse VAR Word remoteCode VAR Word Countr VAR Word x VAR Word DegF VAR Word DegFold VAR Word setemp VAR Word setempold VAR Word I VAR Word time VAR Word fanCtrl VAR Word running VAR Word y VAR Word ' -----[ Initialize ]----------------------------------------------------- READ 0, Setemp ' Read EEPROM load stored desired temp HIGH LCDPin ' Set pin high to be a serial port 'PAUSE 150 FOR I = 0 TO 75 GOSUB get_temp 'DEBUG? degf NEXT SEROUT LCDpin, Baud, [lcdcls] SEROUT lcdpin, baud, [lcdon] PAUSE 5 SEROUT LCDpin, Baud, ["Actual Temp F"] SEROUT lcdpin, baud, ["Desired Temp F"] SEROUT LCDpin, Baud, ["Status= Fan= "] SEROUT lcdpin, baud, ["****date****time****"] SEROUT LCDpin, baud, [defchr0, $04,$04,$04,$04,$04,$04,$04,$04] SEROUT LCDpin, baud, [defchr1, $01,$02,$02,$04,$04,$08,$08,$10] SEROUT LCDpin, baud, [defchr2, $00,$00,$00,$1F,$00,$00,$00,$00] SEROUT LCDpin, baud, [defchr3, $10,$08,$08,$04,$04,$02,$02,$01] running = 10 'SEROUT lcdpin, baud, [l216] 'SEROUT lcdpin, baud, ["test"] ' -----[ Main Routine ]--------------------------------------------------- Main: DO 'Start main loop COUNT irdet, 35, countr 'Count ir pulses IF countr > 2 THEN GOSUB Temp_Entry 'Listen to data bits GOSUB get_temp 'Get Temperature IF setemp > degF THEN 'Turn heater on? HIGH 15 'output control LOW 14 ' SEROUT lcdpin, baud, [L207] ' SEROUT lcdpin, baud, ["Heat"] ' 'DEBUG "Heat", CR ' ENDIF ' ' IF setemp < degF THEN ' LOW 15 ' HIGH 14 ' SEROUT lcdpin, baud, [L207] ' SEROUT lcdpin, baud, ["Cool"] ' 'DEBUG "Cool", CR ' ENDIF ' ' IF setemp = degF THEN ' LOW 15 ' LOW 14 ' SEROUT lcdpin, baud, [L207] ' SEROUT lcdpin, baud, ["STBY" ] ' 'DEBUG "STBY", CR ' ENDIF ' 'DEBUG? setemp ' 'debug? fanCtrl GOSUB Update_Display ' GOSUB read_light ' ' DEBUG? DegF GOSUB still_going ' LOOP ' ' -----[ Subroutine - temp entry]----------------------------------------- Temp_Entry: GOSUB Get_Ir_Remote_Code 'get command from remote IF remotecode > 9 THEN IF remotecode > 15 AND remotecode < 20 THEN GOSUB Fan_control ENDIF ENDIF setemp = remotecode 'load tens digit into variable SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [" "] 'Clear existing temp SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [DEC setemp] 'Write new temp tens digit DO UNTIL countr < 2 'stop program untill button is released COUNT irdet, 35, countr 'listen to ir and count pulses LOOP 'Loop until button is released GOSUB get_ir_remote_code 'get command from remote setemp = setemp * 10 + remotecode 'load ones digit into variable SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [" "] 'Clear existing temp SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [DEC setemp] 'Write new temp ones digit DO GOSUB get_ir_remote_code 'get command from remote LOOP UNTIL remotecode = enter 'countr < 2 'Loop until enter button is pushed DO COUNT irdet, 35, countr 'Wait for enter button to be released LOOP UNTIL countr < 2 'Loop untill button is released IF (setemp <= 90) AND (setemp => 60) THEN 'Check validity of desired temp WRITE 0, setemp 'Write set temp to eeprom ELSEIF setemp < 60 THEN 'Out of range? setemp = setempold 'Load last good temp SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, ["Too Low"] 'Display error for temp out of range lower than 60 PAUSE 2000 'Time delay SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, [" F"] 'Clear error message SEROUT lcdpin, baud, [L117] 'move cursor SEROUT lcdpin, baud, [DEC setemp] 'load last known temp to display ELSEIF setemp > 90 THEN 'out of range SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, ["Too Hot"] 'Display error for temp out of range higher than 90 setemp = setempold 'load last good temp PAUSE 2000 'Time delay SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, [" F"] 'Clear error Message SEROUT lcdpin, baud, [L117] 'move cursor SEROUT lcdpin, baud, [DEC setemp] 'load last known temp to display ENDIF RETURN 'return to main routine ' -----[ Subroutine - Get Ir Remote Code ]-------------------------------- Get_Ir_Remote_Code: 'DO 'COUNT irdet, 35, countr 'DEBUG? countr 'IF countr < 2 THEN GOTO main remoteCode = 0 ' Clear all bits in remoteCode ' Wait for resting state between messages to end. DO RCTIME IrDet, 1, irPulse LOOP UNTIL irPulse > 1100 ' Measure start pulse. IF out of range, THEN retry at Get_Ir_Remote_Code. RCTIME 9, 0, irPulse IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Ir_Remote_Code ' Get data bit pulses. RCTIME IrDet, 0, irPulse ' Measure pulse IF irPulse > 300 THEN remoteCode.BIT0 = 1 ' Set (or leave clear) bit-0 RCTIME IrDet, 0, irPulse ' Measure next pulse IF irPulse > 300 THEN remoteCode.BIT1 = 1 ' Set (or leave clear) bit-1 RCTIME IrDet, 0, irPulse ' etc IF irPulse > 300 THEN remoteCode.BIT2 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT3 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT4 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT5 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT6 = 1 ' Adjust remoteCode so that keypad keys correspond to the value ' it stores. IF (remoteCode < 10) THEN remoteCode = remoteCode + 1 IF (remoteCode = 10) THEN remoteCode = 0 'COUNT irdet, 35, countr 'DEBUG? countr 'DEBUG? remotecode 'LOOP RETURN ' -----[ Subroutine Get Tempurature ]------------------------------------- Get_temp: HIGH 13 ' Select the DS1620. SHIFTOUT 12, 11, LSBFIRST, [238] ' Send the "start conversions" command. LOW 13 ' Do the command. HIGH 13 ' Select the DS1620. SHIFTOUT 12, 11, LSBFIRST, [170] ' Send the "get data" command. SHIFTIN 12, 11, LSBPRE, [x] ' Get the data. LOW 13 ' End the command. dEGF = X * 9 / 10 + 32 ' Convert the data to degrees F. RETURN ' -----[ update display ]------------------------------------------------- Update_display: IF NOT (degF = degFold) THEN degfold = degf 'DEBUG "updated degF", CR IF degF > 99 THEN SEROUT lcdpin, baud, [L016] SEROUT lcdpin, baud, [DEC degF] ELSEIF degF < 99 AND degF > 9 THEN SEROUT lcdpin, baud, [L017] SEROUT lcdpin, baud, [DEC degF] ELSE: SEROUT lcdpin, baud, [L018] SEROUT lcdpin, baud, [DEC degF] ENDIF ENDIF IF NOT (setemp = setempold) THEN SEROUT lcdpin, baud, [L117] SEROUT lcdpin, baud, [DEC setemp] setempold = setemp 'DEBUG "adjusted Setemp", CR ENDIF RETURN ' -----[ Read_light ]----------------------------------------------------- READ_light: HIGH readlight PAUSE 1 RCTIME readlight, 1, time IF time > 400 THEN SEROUT lcdpin, baud, [lcdblon] ELSE: SEROUT lcdpin, baud, [lcdbloff] ENDIF 'DEBUG? time RETURN ' -----[ Fan_control ]----------------------------------------------------- fan_control: IF (remotecode = volup) OR (remotecode = chup) THEN fanCtrl = Auto SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, [" "] SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, ["Auto"] 'DEBUG "auto" DO UNTIL countr < 2 'stop program untill button is released COUNT irdet, 35, countr 'listen to ir and count pulses LOOP remotecode = 0 ENDIF IF (remotecode = volDn) OR (remotecode = chDn) THEN fanCtrl = alwaysOn SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, [" "] SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, [" On"] 'DEBUG "on" DO UNTIL countr < 2 'stop program untill button is released COUNT irdet, 35, countr 'listen to ir and count pulses LOOP ENDIF remotecode = 0 GOTO main ' -----[ still_going ]----------------------------------------------------- still_going: 'FOR y = 1 TO 20 'IF y => 21 THEN y = 1 'IF y < 19 THEN GOTO main 'DEBUG? y 'NEXT running = running + 1 y = running / 10 - 1 IF running => 50 THEN running = 10 SEROUT lcdpin, baud, [L013] SEROUT lcdpin, baud, [y] DEBUG? running DEBUG? y RETURNAlso revise your usage of RCTIME in DO / LOOP
See RCTIME command - state parameter
"State is a variable/constant/expression (0 - 1) that specifies the desired state to measure. Once Pin is not in State, the command ends and stores the result in Variable. "
Here is a simple test - reads state od pin 0 once:
DEBUG ? IrDet
DEBUG BIN16 ? INS
DEBUG ? irPulse
'DO
RCTIME IrDet, 0, irPulse
DEBUG ? IrDet
DEBUG ? irPulse
'STOP
'LOOP UNTIL irPulse > 1100
DEBUG BIN16 ? INS
DEBUG "stop",CR
STOP
Vaclav
Second - the temperature conversion algorithm is incorrect - remember that BS uses integer math only.
' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ EEPROM Data ]----------------------------------------------------- DATA 72, 0 ' -----[ I/O Definitions ]------------------------------------------------ IrDet PIN 9 ' -----[ Constants ]------------------------------------------------------ ' SONY TV IR remote constants for non-keypad buttons readlight PIN 8 Enter CON 11 ChUp CON 16 ChDn CON 17 VolUp CON 18 VolDn CON 19 Power CON 21 Mute CON 20 Prev CON 59 Menu CON 96 Ext CON 99 Frmat CON 61 auto CON 1 alwayson CON 0 defchr0 CON 248 defchr1 CON 249 defchr2 CON 250 defchr3 CON 251 defchr4 CON 252 defchr5 CON 253 defchr6 CON 254 defchr7 CON 255 lcdpin CON 0 Baud CON 32 LcdBLon CON $11 LcdBLoff CON $12 LcdCls CON $0C ' clear LCD (use PAUSE 5 after) Lcdon CON 22 L013 CON 141 L016 CON 144 L017 CON 145 L018 CON 146 L113 CON 161 L114 CON 162 L116 CON 164 L117 CON 165 L118 CON 166 L207 CON 175 L216 CON 184 ' -----[ Variables ]------------------------------------------------------ irPulse VAR Word remoteCode VAR Word Countr VAR Word x VAR Word DegF VAR Word DegFold VAR Word setemp VAR Word setempold VAR Word I VAR Word time VAR Word fanCtrl VAR Word running VAR Word y VAR Word ' -----[ Initialize ]----------------------------------------------------- READ 0, Setemp ' Read EEPROM load stored desired temp READ 1, fanCtrl HIGH LCDPin ' Set pin high to be a serial port 'PAUSE 150 FOR I = 0 TO 75 GOSUB get_temp 'DEBUG? degf NEXT SEROUT LCDpin, Baud, [lcdcls] SEROUT lcdpin, baud, [lcdon] PAUSE 5 SEROUT LCDpin, Baud, ["Actual Temp F"] SEROUT lcdpin, baud, ["Desired Temp F"] SEROUT LCDpin, Baud, ["Status= Fan= "] SEROUT lcdpin, baud, ["****date****time****"] SEROUT lcdpin, baud, [l216] SEROUT lcdpin, baud, [" "] SEROUT lcdpin, baud, [L216] IF fanCtrl = 1 THEN SEROUT lcdpin, baud, ["Auto"] ELSE: SEROUT lcdpin, baud, [" On"] ENDIF SEROUT LCDpin, baud, [defchr0, $04,$04,$04,$04,$04,$04,$04,$04] SEROUT LCDpin, baud, [defchr1, $01,$02,$02,$04,$04,$08,$08,$10] SEROUT LCDpin, baud, [defchr2, $00,$00,$00,$1F,$00,$00,$00,$00] SEROUT LCDpin, baud, [defchr3, $10,$08,$08,$04,$04,$02,$02,$01] running = 0 'SEROUT lcdpin, baud, [l216] 'SEROUT lcdpin, baud, ["test"] ' -----[ Main Routine ]--------------------------------------------------- Main: DO GOSUB get_temp 'Get Temperature DEBUG? degf GOSUB Incoming_IR 'Listen to IR Port GOSUB Update_Display 'Check for changes and update GOSUB Incoming_IR 'Listen to IR Port GOSUB read_light 'Check light and control lcd back light GOSUB Incoming_IR 'Listen to IR Port GOSUB still_going 'Update Graphic (signifies program flow) GOSUB Incoming_IR 'Listen to IR Port GOSUB temp_control 'Check desired and current temp make it comfortable LOOP 'Do it again ' -----[ Subroutine - Incoming IR ]--------------------------------------- Incoming_IR: PULSIN irdet, 0, irpulse 'DEBUG? irpulse IF irpulse > 1220 AND irpulse < 1230 THEN GOSUB Temp_entry 'DEBUG DEC remoteCode ENDIF RETURN ' -----[ Subroutine - temp entry]----------------------------------------- Temp_Entry: DEBUG "button is pushed", CR GOSUB Get_Ir_Remote_Code 'get command from remote DEBUG "collected ir remote code", CR 'DO 'COUNT irdet, 35, countr 'DEBUG? countr 'LOOP UNTIL countr < 2 'DEBUG "button is released", CR IF remotecode > 9 THEN IF remotecode > 15 AND remotecode < 20 THEN GOSUB Fan_control ENDIF ENDIF setemp = remotecode 'load tens digit into variable SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [" "] 'Clear existing temp SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [DEC setemp] 'Write new temp tens digit DEBUG "Loaded Tens", CR 'DO UNTIL countr < 2 'stop program untill button is released 'COUNT irdet, 35, countr 'listen to ir and count pulses 'LOOP 'Loop until button is released GOSUB get_ir_remote_code 'get command from remote setemp = setemp * 10 + remotecode 'load ones digit into variable SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [" "] 'Clear existing temp SEROUT lcdpin, baud, [L117] 'Move cursor SEROUT lcdpin, baud, [DEC setemp] 'Write new temp ones digit DEBUG "Loaded Ones", CR DO GOSUB get_ir_remote_code 'get command from remote LOOP UNTIL remotecode = enter 'countr < 2 'Loop until enter button is pushed DEBUG "enter button pushed", CR 'DO 'COUNT irdet, 35, countr 'Wait for enter button to be released 'LOOP UNTIL countr < 2 'Loop untill button is released 'DEBUG"enter button released", CR IF (setemp <= 90) AND (setemp => 60) THEN 'Check validity of desired temp WRITE 0, setemp 'Write set temp to eeprom ELSEIF setemp < 60 THEN 'Out of range? setemp = setempold 'Load last good temp SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, ["Too Low"] 'Display error for temp out of range lower than 60 PAUSE 2000 'Time delay SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, [" F"] 'Clear error message SEROUT lcdpin, baud, [L117] 'move cursor SEROUT lcdpin, baud, [DEC setemp] 'load last known temp to display ELSEIF setemp > 90 THEN 'out of range SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, ["Too Hot"] 'Display error for temp out of range higher than 90 setemp = setempold 'load last good temp PAUSE 2000 'Time delay SEROUT lcdpin, baud, [L113] 'Move cursor SEROUT lcdpin, baud, [" F"] 'Clear error Message SEROUT lcdpin, baud, [L117] 'move cursor SEROUT lcdpin, baud, [DEC setemp] 'load last known temp to display ENDIF RETURN 'return to main routine ' -----[ Subroutine - Get Ir Remote Code ]-------------------------------- Get_Ir_Remote_Code: 'DO 'COUNT irdet, 35, countr 'DEBUG? countr 'IF countr < 2 THEN GOTO main remoteCode = 0 ' Clear all bits in remoteCode ' Wait for resting state between messages to end. DO RCTIME IrDet, 1, irPulse LOOP UNTIL irPulse > 1100 ' Measure start pulse. IF out of range, THEN retry at Get_Ir_Remote_Code. RCTIME 9, 0, irPulse IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Ir_Remote_Code ' Get data bit pulses. RCTIME IrDet, 0, irPulse ' Measure pulse IF irPulse > 300 THEN remoteCode.BIT0 = 1 ' Set (or leave clear) bit-0 RCTIME IrDet, 0, irPulse ' Measure next pulse IF irPulse > 300 THEN remoteCode.BIT1 = 1 ' Set (or leave clear) bit-1 RCTIME IrDet, 0, irPulse ' etc IF irPulse > 300 THEN remoteCode.BIT2 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT3 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT4 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT5 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT6 = 1 ' Adjust remoteCode so that keypad keys correspond to the value ' it stores. IF (remoteCode < 10) THEN remoteCode = remoteCode + 1 IF (remoteCode = 10) THEN remoteCode = 0 DO COUNT irdet, 35, countr 'DEBUG? countr 'DEBUG? remotecode LOOP UNTIL countr < 2 DEBUG "Button is released", CR RETURN ' -----[ Subroutine Get Tempurature ]------------------------------------- Get_temp: HIGH 13 ' Select the DS1620. SHIFTOUT 12, 11, LSBFIRST, [238] ' Send the "start conversions" command. LOW 13 ' Do the command. HIGH 13 ' Select the DS1620. SHIFTOUT 12, 11, LSBFIRST, [170] ' Send the "get data" command. SHIFTIN 12, 11, LSBPRE, [x] ' Get the data. LOW 13 ' End the command. dEGF = X * 9 / 10 + 32 ' Convert the data to degrees F. RETURN ' -----[ update display ]------------------------------------------------- Update_display: IF NOT (degF = degFold) THEN degfold = degf 'DEBUG "updated degF", CR IF degF > 99 THEN GOTO main ELSEIF degF < 99 AND degF > 9 THEN SEROUT lcdpin, baud, [L017] SEROUT lcdpin, baud, [DEC degF] ELSE: SEROUT lcdpin, baud, [L018] SEROUT lcdpin, baud, [DEC degF] ENDIF ENDIF IF NOT (setemp = setempold) THEN SEROUT lcdpin, baud, [L117] SEROUT lcdpin, baud, [DEC setemp] setempold = setemp 'DEBUG "adjusted Setemp", CR ENDIF RETURN ' -----[ Read_light ]----------------------------------------------------- READ_light: HIGH readlight PAUSE 1 RCTIME readlight, 1, time IF time > 400 THEN SEROUT lcdpin, baud, [lcdblon] ELSE: SEROUT lcdpin, baud, [lcdbloff] ENDIF 'DEBUG? time RETURN ' -----[ Fan_control ]----------------------------------------------------- fan_control: IF (remotecode = volup) OR (remotecode = chup) THEN fanCtrl = Auto SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, [" "] SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, ["Auto"] WRITE 1, fanCtrl 'DEBUG "auto" DO UNTIL countr < 2 'stop program untill button is released COUNT irdet, 35, countr 'listen to ir and count pulses LOOP remotecode = 0 ENDIF IF (remotecode = volDn) OR (remotecode = chDn) THEN fanCtrl = alwaysOn SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, [" "] SEROUT lcdpin, baud, [L216] SEROUT lcdpin, baud, [" On"] 'DEBUG "on" DO UNTIL countr < 2 'stop program untill button is released COUNT irdet, 35, countr 'listen to ir and count pulses LOOP ENDIF remotecode = 0 GOTO main ' -----[ still_going ]----------------------------------------------------- still_going: IF running => 4 THEN running = 0 SEROUT lcdpin, baud, [L013] SEROUT lcdpin, baud, [running] running = running + 1 'DEBUG? running 'DEBUG? y RETURN ' -----[ subroutine Temp_Control ]----------------------------------------- Temp_Control: IF setemp > degF THEN 'Turn heater on? HIGH 15 'output control LOW 14 ' SEROUT lcdpin, baud, [L207] ' SEROUT lcdpin, baud, ["Heat"] ' 'DEBUG "Heat", CR ' ENDIF ' ' IF setemp < degF THEN ' LOW 15 ' HIGH 14 ' SEROUT lcdpin, baud, [L207] ' SEROUT lcdpin, baud, ["Cool"] ' 'DEBUG "Cool", CR ' ENDIF ' ' IF setemp = degF THEN ' LOW 15 ' LOW 14 ' SEROUT lcdpin, baud, [L207] ' SEROUT lcdpin, baud, ["STBY" ] ' 'DEBUG "STBY", CR ' ENDIF ' 'DEBUG? setemp ' 'debug? fanCtrl RETURNIt works... I put everything into sub routines and then interlaced the functions so that it would respond to the remote commands better.
Also with the temperature calculation. I thought that because the BS2 only works with interger math that it would just trunicate the decimal if the calculation resulted in one. is there a better way to do it? more precision with bs2 and the interger limitation?
Edit your original post - use "edit" " go advanced" and select from pull down box. ( upper left corner I believe)
By the way your temparatire conversion constant is also wrong.
Here is one way to get fractions into the conversion .
' {$STAMP BS2e} ' {$PBASIC 2.5} X VAR Word F VAR Word Fraction VAR Word Unit VAR Word DEBUG "Input celsius " DEBUGIN DEC X DEBUG CR '°C x 9/5 + 32 = °F X = X * 100 f = x * 9/5 + 3200 DEBUG ? f Fraction = f // 100 DEBUG ? Fraction Unit = f / 100 DEBUG ? Unit