'1-of-3 Pushbutton/LED control...Simulation tested only
'PICAXE 14M
'Inputs 0,1,2 ...decimal 0=None, 1=Red, 2=Amber, 4=Green, 7=3 LSB
'Outputs 0,1,2 ...decimal 0=None, 1=Red, 2=Amber, 4=Green, 7=All
'For use with 1of3 Toggle 3.sch
'1of3toggle.bas
'Ken Moffett
Start: 'Power-up
Let pins = 0 'Turn off all LEDs
Recovery: 'Check last LED selection before power-off
Peek $50, b0 'Retrieve last LED selection from static memory
b0 = b0 & 7 'Mask for lower 3 inputs
'b0 = 0 '> simulated error <
If b0 = 1 then LED 'Last PB was Red
If b0 = 2 then LED 'Last PB was Amber
If b0 = 4 then LED 'Last PB was Green
Goto Flash 'Static memory $50 empty or invalid data
LED: 'Store and turn on selected LED
Poke $50, b0 'Store LED selection in static memory
Let pins = b0 'Light selected LED
Gosub PBup 'Check for PB up
Goto PBdown 'Check if PB still down
PBdown: 'Check if PB still down
b0 = pins & 7 'Retrieve and mask for lower 3 inputs
If b0 = 1 then LED 'Red PB pushed
If b0 = 2 then LED 'Amber PB pushed
If b0 = 4 then LED 'Green PB pushed
goto PBdown 'No buttons pushed
PBup: 'Check for PB up
b0 = pins & 7 'Retrieve and mask for lower 3 inputs
If b0 <> 0 then PBup 'Check if any PB still down
Return
Flash: 'Flash all LEDs until valid PB down
Let pins = 7 'Turn on all LEDs
Pause 250 'Pause 250 mS
Let pins = 0 'Turn off all LEDs
Pause 250 'Pause 250 mS
Let b0 = pins & 7 'Retrieve and mask for lower 3 inputs
If b0 = 1 then LED 'Red PB pushed
If b0 = 2 then LED 'Amber PB pushed
If b0 = 4 then LED 'Green PB pushed
Goto Flash
End 'Halt program