'{$STAMP BS2}
'{$PBASIC 2.0}
'Program 1.2, Simple Heater
LED1 VAR  OUT4                  'LED1 is on P4
RC  CON 7                       'RC network is on Pin 7
Temp  VAR Word                  'Pot is a variable to hold results

OUTPUT 4                        'Setup LED as output
LED1 = 1                        'Energize intitially

Main:
  GOSUB ReadTemp                'Read pot value as temperature
  GOSUB CheckTemp               'check temp to setpoint
  PAUSE 250
GOTO Main

ReadTemp
  HIGH RC                       'Read Potentionmeter
  PAUSE 10
  RCTIME RC, 1, Temp
  Temp = Temp/30                'Scale the results down
                                'store as temperature
  DEBUG "Temp =",DEC Temp, CR
RETURN

CheckTemp:                      'If Temp > 100, or heat already on,
                                'check if should be off
  IF (Temp > 100) OR (LED1 = 1) THEN CheckOff
  LED1=1                        'If not, then energize and display
  DEBUG "The heater energized",CR

Checkoff:                       'If Temp < 120 or heat is off already, all done
  IF (Temp < 120) OR (LED1 = 0) THEN CheckDone
  LED1 = 0                      'if not, the enrgize and display
  DEBUG "The heater de-energized" , CR
CheckDone:
RETURN
