Exclusive PICAXE code
‘ # exclusive.bas Robert Stave 2008
‘ # Simple PICAXE program to set pins where
‘ # the voltage on input 4 is translated to
‘ # 4 states (000, 100, 110, 111)
‘ #
‘ # Added code to simulate hysteresis
symbol readValue =4
symbol v0 = 0
symbol v1 = 1
symbol v2 = 2
symbol tmpValue=b10
symbol state = b8
init:
‘ ## initialize it all pins to zero
low v0
low v1
low v2
state = 0;
start:
‘ ### read value
readadc readValue,tmpValue
if tmpValue < 64 then stateZero
if tmpValue < 128 then stateOne
if tmpValue < 192 then stateTwo
stateThree:
low v0
low v1
high v2
state = 3
goto start
stateTwo:
‘ # check if we are above 186 if so and we
‘ # are coming from 3, just ignore it for now
if tmpValue > 186 then
if state = 3 then
goto start
endif
endif
low v0
high v1
low v2
state = 2
goto start
stateOne:
‘ # check if we are above 120 if so and we
‘ # are coming from 2, just ignore it for now
if tmpValue > 120 then
if state = 2 then
goto start
endif
endif
high v0
low v1
low v2
state = 1
goto start
stateZero:
‘ # check if we are above 58 if so and we
‘ # are coming from 1, just ignore it for now
if tmpValue > 58 then
if state = 1 then
goto start
endif
endif
low v0
low v1
low v2
state = 0
goto start