button count Game project problem
I am making a button count Game project. I use the "pulsin" command
to count the no. of button pushed. When I push the button faster, the
LED bar graph will rise higer. However, sometimes, the LED bar graph
will suddenly rise to the highest position. Could anyone please help
me to solve it ? Or anyone have some ideas for this project ? Thanks.
Here's my program:'Button Count Game
cycles var word
start var byte
period var word
counter var byte
pattern var byte
n var word
dirs = $ffff
start = 0
check:
outs = %10000000000000
freqout 15,500,950,2500
'Push Start Botton to Start
play:
BUTTON 11, 1,255,0,start,1,loop 'press start button to start
goto play
loop:
'debug cls
'debug "start!", cr
'pause 1000: debug "Read, set...",cr: pause 500
'debug "go!", cr: pause 100
n = 0
cycles = 0
outs = %01000000000000
freqout 15,500,950,2500
pause 50
for counter = 1 to 30
playing:
outs = n
n = n/2 ' decrease the position
debug "counter: ", dec counter, cr
pulsin 10,1,cycles 'count the cycles of button pressed
'count 10,period,cycles 'count How Fast
debug "cycles: ", dec cycles
if 5 > cycles AND cycles >= 1 then one ' rise 1 LED
if 10 > cycles AND cycles >= 5 then two 'rise 2 LED
if 15 > cycles AND cycles >= 10 then three 'rise 3
if 25 > cycles AND cycles >= 20 then four 'rise 4
if 30 > cycles AND cycles >= 25 then five 'rise 5
if 35 > cycles AND cycles >= 30 then six 'rise 6
if 40 > cycles AND cycles >= 35 then seven 'rise 7
if 45 > cycles AND cycles >= 40 then eight 'rise 8
if 50 > cycles AND cycles>= 45 then nine 'rise 9
if 55 > cycles AND cycles >=50 then ten 'rise 10
if cycles >= 55 OR 1 < cycles then zero 'goto zero
next
goto check
zero:
n = n /2
goto playing
one:
n = 1
goto playing
two:
outs = 1 : pause 10
n = 2
goto playing
three:
outs = 1 : pause 10
outs = 2 : pause 10
n = 4
goto playing
four:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
n = 8
goto playing
five:
debug "very very fast", cr
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
n = 16
goto playing
six:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16: pause 10
n = 32
goto playing
seven:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
n = 64
goto playing
eight:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
outs = 64 : pause 10
n = 128
goto playing
nine:
outs = 10 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
outs = 64 : pause 10
outs = 128 : pause 10
n = 256
goto playing
ten:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 80 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
outs = 64 : pause 10
outs = 128 : pause 10
outs = 256 : pause 120
outs = 512
for f = 0 to 20
freqout 15,1000,f+20,3500
n = 512
goto playing
Thank you.
to count the no. of button pushed. When I push the button faster, the
LED bar graph will rise higer. However, sometimes, the LED bar graph
will suddenly rise to the highest position. Could anyone please help
me to solve it ? Or anyone have some ideas for this project ? Thanks.
Here's my program:'Button Count Game
cycles var word
start var byte
period var word
counter var byte
pattern var byte
n var word
dirs = $ffff
start = 0
check:
outs = %10000000000000
freqout 15,500,950,2500
'Push Start Botton to Start
play:
BUTTON 11, 1,255,0,start,1,loop 'press start button to start
goto play
loop:
'debug cls
'debug "start!", cr
'pause 1000: debug "Read, set...",cr: pause 500
'debug "go!", cr: pause 100
n = 0
cycles = 0
outs = %01000000000000
freqout 15,500,950,2500
pause 50
for counter = 1 to 30
playing:
outs = n
n = n/2 ' decrease the position
debug "counter: ", dec counter, cr
pulsin 10,1,cycles 'count the cycles of button pressed
'count 10,period,cycles 'count How Fast
debug "cycles: ", dec cycles
if 5 > cycles AND cycles >= 1 then one ' rise 1 LED
if 10 > cycles AND cycles >= 5 then two 'rise 2 LED
if 15 > cycles AND cycles >= 10 then three 'rise 3
if 25 > cycles AND cycles >= 20 then four 'rise 4
if 30 > cycles AND cycles >= 25 then five 'rise 5
if 35 > cycles AND cycles >= 30 then six 'rise 6
if 40 > cycles AND cycles >= 35 then seven 'rise 7
if 45 > cycles AND cycles >= 40 then eight 'rise 8
if 50 > cycles AND cycles>= 45 then nine 'rise 9
if 55 > cycles AND cycles >=50 then ten 'rise 10
if cycles >= 55 OR 1 < cycles then zero 'goto zero
next
goto check
zero:
n = n /2
goto playing
one:
n = 1
goto playing
two:
outs = 1 : pause 10
n = 2
goto playing
three:
outs = 1 : pause 10
outs = 2 : pause 10
n = 4
goto playing
four:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
n = 8
goto playing
five:
debug "very very fast", cr
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
n = 16
goto playing
six:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16: pause 10
n = 32
goto playing
seven:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
n = 64
goto playing
eight:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
outs = 64 : pause 10
n = 128
goto playing
nine:
outs = 10 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 8 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
outs = 64 : pause 10
outs = 128 : pause 10
n = 256
goto playing
ten:
outs = 1 : pause 10
outs = 2 : pause 10
outs = 4 : pause 10
outs = 80 : pause 10
outs = 16 : pause 10
outs = 32 : pause 10
outs = 64 : pause 10
outs = 128 : pause 10
outs = 256 : pause 120
outs = 512
for f = 0 to 20
freqout 15,1000,f+20,3500
n = 512
goto playing
Thank you.
Comments
your problem is due to contact bounce.
when a mechanical switch or button is opened and closed, it doesn't make a
perfect connection right away (this is why lots of audio equipment makes pops
and clicks when you flip switches.) these noises are called contact bounce,
and the stamp is fast enough to 'see' them happening, so instead of counting
the one pulse on the button, you're counting the many pulses from the bounce
of the contact.
Jason Lavoie
Felix Chan <flexchan@h...> said:
> I am making a button count Game project. I use the "pulsin" command
> to count the no. of button pushed. When I push the button faster, the
> LED bar graph will rise higer. However, sometimes, the LED bar graph
> will suddenly rise to the highest position. Could anyone please help
> me to solve it ? Or anyone have some ideas for this project ? Thanks.
slightly slower that it is humanly possible to push the button - this should
be long enough to allow the bounce to damp out. my 1st guess would be
something like the equiv of "delay(0.001)"
richard
Original Message
From: <jlavoie@e...>
To: <basicstamps@egroups.com>
Sent: Monday, June 26, 2000 8:13 AM
Subject: Re: [noparse][[/noparse]basicstamps] button count Game project problem
> I haven't examined your code very thoroughly, but there's a 99% chance
that
> your problem is due to contact bounce.
> when a mechanical switch or button is opened and closed, it doesn't make a
> perfect connection right away (this is why lots of audio equipment makes
pops
> and clicks when you flip switches.) these noises are called contact
bounce,
> and the stamp is fast enough to 'see' them happening, so instead of
counting
> the one pulse on the button, you're counting the many pulses from the
bounce
> of the contact.
>
> Jason Lavoie
>
> Felix Chan <flexchan@h...> said:
>
> > I am making a button count Game project. I use the "pulsin" command
> > to count the no. of button pushed. When I push the button faster, the
> > LED bar graph will rise higer. However, sometimes, the LED bar graph
> > will suddenly rise to the highest position. Could anyone please help
> > me to solve it ? Or anyone have some ideas for this project ? Thanks.
>
>
>
>
>