State machine with BS2
I am looking for a sample code written in Parallax basic implementing state machine.
I am·coding·four state system and just need something to get me started on my project.
Thanks for reading
·
·
I am·coding·four state system and just need something to get me started on my project.
Thanks for reading
·
·

Comments
state VAR Nib dur VAR Byte buttons VAR INA ' active low buttons on pins 0-3 leds VAR OUTD ' 4 leds on pins 12-15 DIRA = %0000 DIRD = %1111 Start: state = $F dur = 255 Main: Parse_Timer: IF dur > 0 THEN dur = dur - 1 ENDIF PAUSE 100ms ' 100ms "frame" for state machine Parse_States: ON state GOTO state_00, state_01, state_02, state_03 ' etc state_04: ' and higher since they are not defined above -- waiting for "release" IF buttons = 0 THEN state = $0 ENDIF GOTO States_Done state_03: ' wait for timeout, then see if no buttons pressed IF dur = 0 THEN state = $4 ENDIF GOTO States_Done state_02: ' wait for button 3 to be pressed, if times out, restart state machine IF buttons.BIT3 = 1 THEN state = $3 dur = 50 ' 5 seconds ELSEIF dur = 0 THEN state = $0 ENDIF GOTO States_Done state_01: ' wait for button 1 to be pressed, if times out, restart state machine IF buttons.BIT1 = 1 THEN state = $3 dur = 50 ' 5 seconds ELSEIF dur = 0 THEN state = $0 ENDIF GOTO States_Done state_00: ' wait for button, if it's 0 or 3, then wait for 1 or 4 to be pressed within several seconds IF buttons = %0001 THEN ' won't work with simulataneous button presses state = $1 dur = 20 ' user must press other button within 2 seconds! ELSEIF buttons = %0100 THEN state = $2 dur = 10 ' user must press other button within 1 seconds! fast! ENDIF ' GOTO States_Done States_Done: leds = state ' show 4 bit state on leds DEBUG HOME, "state:", IHEX1 state, " dur:",DEC3 dur, CLREOL ' more code, say outputting results of state machine actions GOTO Main▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Post Edited (Carl Hayes) : 2/10/2009 9:40:05 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Post Edited (Carl Hayes) : 2/10/2009 9:38:19 PM GMT
I have examples of PBASIC state machines posted at,
www.emesys.com/BS2fsm.htm
buttons, keypads, encoders, game. Good luck stamping!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com