Shop OBEX P1 Docs P2 Docs Learn Events
Skipping a whole part of code — Parallax Forums

Skipping a whole part of code

mfavs327mfavs327 Posts: 11
edited 2008-03-13 02:50 in BASIC Stamp
I am new to programming the basic stamp and i am creating a project using it.· the project has five buttons connected to five pins on the input of the bS2.· when the first button is pressed (pin 0) the letters on the other four buttons change( the other buttons are connected to pins 1, 2,3 and 4 respectively). when any other button is pressed a letter is typed using the serout command.· i have 10 groups of letters but every time i press the first button it skips a whole group.· everything else works great except for that.

here is a piece of the code:
ASDF:
· DEBUG "in ASDF loop"
PAUSE 1000
LOW OUT15
LOW OUT14
LOW OUT13
LOW OUT12
THERE:
·DEBUG "before button"
IF IN0 = 1 THEN GOTO JKL
PAUSE 1000
·DEBUG "after button"

IF IN1 = 1 THEN GOTO HERE1
IF IN2 = 1 THEN GOTO HERE2
IF IN3 = 1 THEN GOTO HERE3
IF IN4 = 1 THEN GOTO HERE4
GOTO THERE
HERE1:
· SEROUT 16, 16468, [noparse][[/noparse]A]
· PAUSE 1000
GOTO THERE
HERE2:
· SEROUT 16, 16468, [noparse][[/noparse]S]
· PAUSE 1000
GOTO THERE
HERE3:
· SEROUT 16, 16468, [noparse][[/noparse]68]
· PAUSE 1000
GOTO THERE
HERE4:
· SEROUT 16, 16468, [noparse][[/noparse]70]
· PAUSE 1000
GOTO THERE

JKL:
PAUSE 1000
LOW OUT15
LOW OUT14
LOW OUT13
HIGH OUT12
THERE1:
IF IN0 = 1 THEN GOTO QWER


IF IN1 = 1 THEN GOTO J
IF IN2 = 1 THEN GOTO K
IF IN3 = 1 THEN GOTO L
IF IN4 = 1 THEN GOTO JKLL
GOTO THERE1
J:
· SEROUT 16, 16468, [noparse][[/noparse]74]
· PAUSE 1000
GOTO THERE1
K:
· SEROUT 16, 16468, [noparse][[/noparse]75]
· PAUSE 1000
GOTO THERE1
L:
· SEROUT 16, 16468, [noparse][[/noparse]76]
· PAUSE 1000
GOTO THERE1
JKLL:
· SEROUT 16, 16468, [noparse][[/noparse]59]
· PAUSE 1000
GOTO THERE1
QWER:

In my situation every button works (the letter buttons) but when i hit the first button it totally skips the JKL group of letters to the QWER group.· which the QWER group works perfectly.· please advise.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-12 22:20
    I think your problem is that you don't wait for the button to be released. When you push the first button, the program jumps to a second section where the button state is tested again and it's still pressed, so the program jumps again.
  • mfavs327mfavs327 Posts: 11
    edited 2008-03-12 22:24
    i thought that too thats why i put pauses in there... and i take my hand off as fast as i can ... but it still does that
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-03-12 22:58
    It's executing 2,000 instructions PER SECOND. You can MAYBE press and release in 1/10 of a second -- during which the BS2 will have executed 200 instructions.

    Welcome to real-time programming.
  • mfavs327mfavs327 Posts: 11
    edited 2008-03-12 23:00
    what do you think i should do then allanlane5
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-13 00:49
    For example, at JKL, put the following:
    IF IN0 = 1 THEN JKL
    This will wait for button 0 to be released before continuing.
    Do something similar at J, K, L, and JKLL and at HERE1, HERE2, HERE3, and HERE4.
    There are ways to reorganize the code to simplify this and to combine like bits of code,
    but this will get you started.
  • FranklinFranklin Posts: 4,747
    edited 2008-03-13 01:52
    I notice you GOTO there1 but you have no there1 could you attach the code you are testing?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • mfavs327mfavs327 Posts: 11
    edited 2008-03-13 02:50
    i have nothing to there1 cause it was the rest of my code... i only sent you a small portion.... but i fixed the problem with the button comand saying... BUTTON 0,1,255,255,btn,1,JKL and it works perfectly now... thanks
Sign In or Register to comment.