Shop OBEX P1 Docs P2 Docs Learn Events
sequences and input — Parallax Forums

sequences and input

kazkaz Posts: 2
edited 2006-02-14 18:39 in Learn with BlocklyProp
hi,

we are trying to make our stamp listen for an input sequence. we've tried embeded if statements and they don't seem to want to work.

anyone know how to make this work?

Comments

  • edited 2006-02-14 17:59
    Could you be a little more specific? What sequence are you looking for? Please also post the code you using to discern the sequence.
  • kazkaz Posts: 2
    edited 2006-02-14 18:17
    we are looking to use switches attached to the feet of the user to control a robot's motion.

    so, we are trying to figure out how to make the stamp listen for when 1 switch is pressed then another.

    something like this:

    if switch1 = 1 then switch2 = 1
    do this

    that part is easy, but we also need it to do the reverse

    so

    if switch1 = 1 then switch2 = 1
    do this
    if switch2 = 1 then switch1 = 1
    do this2

    so we need the stamp to distinguish the order of the switches being triggered
  • edited 2006-02-14 18:31
    Your design is commonly referred to as a state machine.· Here is a an example of a simple PBASIC state machine; hope·it helps.· Good luck with your robot design.

    state VAR Nib
    stateOld VAR Nib

    DO

    · state.bit0 = switch1
    · state.bit1 = switch2

    · IF state <> stateOld THEN

    ··· SELECT state
    ····· CASE %00
    ·······action = Do_Something
    ···· CASE %01
    ······ action = Do_Another_Thing
    ···· CASE %10
    ······ action = Do_That_Other_Thing
    ···· CASE %11
    ······ action = Fall_Over
    ···· ENDSELECT

    · ENDIF

    · GOSUB Perform_Action

    · stateOld = state

    LOOP
  • edited 2006-02-14 18:39
    Oops, sorry.· The previous post did not deal with the previous state of the switches.··Here is a modified example·that makes decisions based on·both the·previous and current states of the switches.·

    state VAR Nib
    stateOld VAR Nib

    DO

    · state.bit0 = switch1
    · state.bit1 = switch2

    · IF state <> stateOld THEN

    · · IF state = %01 AND stateOld = %10 THEN
    · ··· action = Do_Something
    ·· ·ELSEIF state = %01 AND stateOld = %11 THEN
    ·· ·· action = Do_Another_Thing
    ··· ELSEIF state = %10 AND stateOld = %00 THEN
    ····· action = Do_That_Other_Thing
    ···· .
    ·· · .
    ··· ·.
    ·· ·ENDIF

    · ENDIF

    · GOSUB Perform_Action

    · stateOld = state

    LOOP

    Post Edited (Andy Lindsay (Parallax)) : 2/14/2006 6:49:14 PM GMT
Sign In or Register to comment.