' {$STAMP BS2}
' {$PBASIC 2.5}
Light VAR OUTL                              ' Light is a variable that drives the low byte high (1) or Low (0)
cnt VAR Word                                ' cnt is a word sized variable that records the output signal form  the 555 timer.
                                            ' This value will change during the measurement condcutivity
DO
HIGH 9                                      ' Turn on the 555 oscillation.
COUNT 10, 1000, cnt                         ' Count for one second.
DEBUG HOME, "cnt = ", DEC5 cnt              ' Show values in the debug terminal.
DIRL=%11111111                              ' Configure all pins (0-7) in the Low Byte as outputs
IF (cnt =0) THEN                            ' If the value of Cnt is 0,
  Light=%00011111                           ' Then drive pins 0 - 5 High
  PAUSE 100                                 ' Hold for 100 millseconds (0.1 s)
  Light=%00000000                           ' Then drive pins 0 - 5 Low
  PAUSE 100                                 ' Hold for 100 millseconds (0.1 s)
ELSEIF (cnt <=900 ) THEN                    ' Otherwise, if the value of Cnt is less than or equal to 900,
    Light=%00000000                         ' Then drive pins 0 - 5 Low (Turn off all LEDs). This should correspond to the meter being placed in water.
ELSEIF  (cnt>901 AND cnt<= 1200) THEN        ' Otherwise, if the value of Cnt is between 901 and 1200,
  Light = %00000001                         ' Then drive pin 0 High (Turn on the 1 LED). This should correspond to the meter being placed in 0.01 M NaCl.
ELSEIF (cnt>1201 AND cnt<= 1700) THEN        ' Otherwise, if the value of Cnt is between 1201 and 1700,
  Light= %00000011                          ' Then drive pins 0 - 1 High (Turn on the 2 LEDs). This should correspond to the meter being placed in 0.02 M NaCl.
ELSEIF (cnt>1701 AND cnt<= 2200) THEN       ' Otherwise, if the value of Cnt is between 1701 and 2200,
  Light=%00000111                           ' Then drive pins 0 - 2 High (Turn on the 3 LEDs). This should correspond to the meter being placed in 0.03 M NaCl.
ELSEIF (cnt>2201 AND cnt<= 3000) THEN       ' Otherwise, if the value of Cnt is between 2201 and 3000,
  Light=%00001111                           ' Then drive pins 0 - 3 High (Turn on the 4 LEDs). This should correspond to the meter being placed in 0.04 M NaCl.
ELSEIF (cnt>3001) THEN                       ' Otherwise, if the value of Cnt greater than 3001,
  Light=%00011111                           ' Then drive pins 0 - 4 High (Turn on all 5 LEDs). This should correspond to the meter being placed in 0.05 M NaCl.
ENDIF                                       ' End if
LOOP                                        ' Back to begining of program. Loop ifinitely.