Shop OBEX P1 Docs P2 Docs Learn Events
Need help on BASIC Language. — Parallax Forums

Need help on BASIC Language.

bbnqondbbnqond Posts: 16
edited 2008-09-28 03:35 in BASIC Stamp
Dear all,

I am currently work on a project using BS2P24 and I would like to seek help here.

I want to doing something like this:

I have connected an active low button to P8 of the stamp. When I press the button, go subroutine A; when i press the button again, stop A and go subroutine B. (Eg, When I press the button, the LED lit; when I press the button again, the LED turns off.)

I have thought of using the Button function, yet I failed to do so. The program succeed in going to subrountine A but failed to return to subrountine B when I pressed the button again. Below shows what I have written:

===========================
led PIN 9
but PIN 8
butWrk VAR Byte

Main:
BUTTON but, 0, 255, btnWrk, 0, B
DEBUG "flame on!"
HIGH 9

B:
LOW 9
DEBUG "Bye~"
============================

Could any big guy help me out?

Regards,
bbnqond

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-09-26 13:10
    Read up on the button command. Notice that it says it must be in a loop. What you want is something like this (psuedocode):

    Main:

    Do
    -Check button
    Loop
    Subroutine A

    Do
    -Check button
    Loop
    Subroutine B

    GOTO Main

    This checks the button constantly until it's pushed, then does subA. It then checks the button until push again, and does subB. It then returns to main (begining) and begins checking again. It's a big loop.
  • bbnqondbbnqond Posts: 16
    edited 2008-09-27 03:34
    SRLM said...
    Read up on the button command. Notice that it says it must be in a loop. What you want is something like this (psuedocode):

    Main:

    Do
    -Check button
    Loop
    Subroutine A

    Do
    -Check button
    Loop
    Subroutine B

    GOTO Main

    This checks the button constantly until it's pushed, then does subA. It then checks the button until push again, and does subB. It then returns to main (begining) and begins checking again. It's a big loop.

    Thz bro, I got the concept now turn.gif
  • SRLMSRLM Posts: 5,045
    edited 2008-09-27 03:49
    To make it a little bit cooler (why not make it difficult?) You could add a fade transition with the LEDs.
  • bbnqondbbnqond Posts: 16
    edited 2008-09-28 03:35
    SRLM said...
    To make it a little bit cooler (why not make it difficult?) You could add a fade transition with the LEDs.

    I wonder if it is possible to read the state of the pin using INPUT..@@?

    IF(pin0 = 1)THEN
    Debug "pin 0 = 1"

    IF(pin0 = 0)THEN
    Debug "pin 0= 0"

    Thz
Sign In or Register to comment.