PDA

View Full Version : Need help on BASIC Language.



bbnqond
09-26-2008, 04:52 PM
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

SRLM
09-26-2008, 09:10 PM
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.

bbnqond
09-27-2008, 11:34 AM
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 http://forums.parallax.com/images/smilies/turn.gif

SRLM
09-27-2008, 11:49 AM
To make it a little bit cooler (why not make it difficult?) You could add a fade transition with the LEDs.

bbnqond
09-28-2008, 11:35 AM
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