'{$STAMP BS2}
'{$PBASIC 2.0}
'Program 1.3, Simple Heater using StampPlot Lite
'Configure StampPlot Lite
PAUSE 500
DEBUG "!SPAN 50,150",CR         'Set span for 50-150
DEBUG "!TMAX 60",CR             'Set for 60 seconds
DEBUG "!PNTS 500",CR            '500 data points per plot
DEBUG "!TITL Simple Heater Control",CR 'Title the form
DEBUG "!SHFT ON",CR             'Allow plot to shift at max
DEBUG "!TSMP ON",CR
DEBUG "!PLOT ON",CR             'Enable plotting
DEBUG "!RSET",CR                'Reset Plot

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 DEC Temp, CR            'Send temperature value
  DEBUG IBIN LED1,CR            'Send LED Status
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
  DEBUG "!USRS The heater is energized!",CR  'Update SPL status bar

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
  DEBUG "!USRS The heater is de-energized",CR    'Update SPL status bar
CheckDone:
RETURN
