Impact Sensor Issue, SOMEONE PLEASE HELP ASAP!
daveetheewavee
Posts: 3
Hello, I am making a program where by blowing into an impact sensor, I am able to turn on an off a fan & on and off a light, so fat I have came up with this code:
' {$STAMP BS2}
' {$PBASIC 2.5}
Impact PIN 0
#SELECT $STAMP
#CASE BS2, BS2E
DurAdj CON $100
#ENDSELECT
Capture CON 2000
i VAR Nib
Main:
DO
DEBUG CLS,
"what do you want me to do?", CR
PAUSE 1000
DEBUG "Ready?"
PAUSE 500
DEBUG "BLOW!", CR
COUNT Impact,(Capture */ DurAdj),i
DEBUG CR, "You blowed ", DEC i, " times", CR
IF i=2 THEN fo
IF i=3 THEN foff
PAUSE 3000
DEBUG "Blow to go again"
DO : LOOP UNTIL (Impact = 0)
LOOP
END
fo:
DEBUG "fan on"
RETURN
foff:
DEBUG "fan off"
RETURN
But I'm having an issue with the impact sensor, when I blow into it once, it would give me a value of 4 or 5, or if I blow into it twice, it was give me a value of like 13 or 14, I need help fixing this problem so that if I blow once, it will give me a value of one & if I blow twice, it will give me a value of two and so on & so forth
' {$STAMP BS2}
' {$PBASIC 2.5}
Impact PIN 0
#SELECT $STAMP
#CASE BS2, BS2E
DurAdj CON $100
#ENDSELECT
Capture CON 2000
i VAR Nib
Main:
DO
DEBUG CLS,
"what do you want me to do?", CR
PAUSE 1000
DEBUG "Ready?"
PAUSE 500
DEBUG "BLOW!", CR
COUNT Impact,(Capture */ DurAdj),i
DEBUG CR, "You blowed ", DEC i, " times", CR
IF i=2 THEN fo
IF i=3 THEN foff
PAUSE 3000
DEBUG "Blow to go again"
DO : LOOP UNTIL (Impact = 0)
LOOP
END
fo:
DEBUG "fan on"
RETURN
foff:
DEBUG "fan off"
RETURN
But I'm having an issue with the impact sensor, when I blow into it once, it would give me a value of 4 or 5, or if I blow into it twice, it was give me a value of like 13 or 14, I need help fixing this problem so that if I blow once, it will give me a value of one & if I blow twice, it will give me a value of two and so on & so forth
Comments
Sorry Dave, but in general you have to use whatever output a sensor sends you. In this case you could compare the value to 8 or 9 and pass a 1 if the input is lower and 2 if it is higher.
So what kind of state-machine type should I use, like what do you recommend I do?