why isn't this button command working?
brettm
Posts: 36
It seems to me this code should blink LED2 until the button at P0 is pressed, then it should blink LED5
However, when I run it, it blinks LED2 twice, then LED5 indefinitely. That's with no button input. Pressing the button changes nothing. The only thing I can get the button to do is if I press it after the first LED2 blink it goes immediately to the LED5 blinks.
What am I not understanding about the button command?
' {$STAMP BS1} ' {$PBASIC 1.0} Main: '--------------------Blink 2 if not pressed--------------------------------------------' HIGH 2 PAUSE 1000 LOW 2 PAUSE 1000 '--------------------Check Button------------------------------------------------------' BUTTON 0, 1, 255, 1, B1, 0, Nothing GOTO BlinkLED5 'NOTE: This happens only if the Button is pressed..... Nothing: GOTO Main: BlinkLED5: HIGH 5 PAUSE 1000 LOW 5 PAUSE 1000 GOTO BlinkLED5
However, when I run it, it blinks LED2 twice, then LED5 indefinitely. That's with no button input. Pressing the button changes nothing. The only thing I can get the button to do is if I press it after the first LED2 blink it goes immediately to the LED5 blinks.
What am I not understanding about the button command?
Comments
HIGH·5
PAUSE·1000
LOW·5
PAUSE·1000
GOTO·BlinkLED5
Change it to GOTO Main
from Vdd to a momentary button to P0
Feels Like the First Time.
okay, good to know, but would it affect this?
I'm not even pressing the button and it won't loop to main
How does this work?
Also, please place the aforementioned resistor, too.
I just tried that new code and it does the same thing, but I didn't add that resistor. I just got this thing and don't have any resistors lying around. I'll go swing by RadioShack and report back later this evening. Maybe that's all there is to it...
Post Edited (PJ Allen) : 6/10/2006 10:01:35 PM GMT
' Led Test .BAS
' {$STAMP BS1}
' {$PBASIC 1.0}
'
[noparse][[/noparse] Declarations ]
SYMBOL btnWrk = B2 ' workspace for BUTTON
'
[noparse][[/noparse] Main Routine ]
Main:
BUTTON 0, 0, 255, 250, btnWrk, 0, Blink_LED5 ' Goto Blink_LED5 if P0 = 1
HIGH 2
PAUSE 1000
LOW 2
PAUSE 1000
Blink_LED5:
HIGH 5
PAUSE 1000
LOW 5
PAUSE 1000
GOTO Main ' repeat endlessly
Good thinking, bennettdan.
thank you!· i figured it would be something dumb and simple like that...
Post Edited (brettm) : 6/11/2006 6:32:12 AM GMT
Resistors are NOT dumb, but they are taken for granted.·
Which reminds of when The Brain, The Eyes, and The Ears got into an argument, each figuring he was "in charge", going on strike in turn.· After each had his turn, with inconclusive results, The Seat announced that he'd show them all: when he stopped then The Brain couldn't think, The Eyes couldn't see, and The Ears couldn't hear.
thanks again! [noparse]:D[/noparse]
[noparse]:D[/noparse]
[noparse]:D[/noparse]
Just as a brief explanation, without the resistor pulling the line into a "known" state (tied to Vcc or Vss) then the input pin on the Stamp "floats" and acts as an antenna...picking up whatever stray signals might be floating around near your rig, causing your Stamp to see either a high or a low, depending on the strength of the "air signal".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...