Debouncing a Push Button
Dmagee
Posts: 20
I don't want to use a PAUSE to debounce the pb so I'm using a flag routine. Counting up the flag debounce works but counting down the debounce did not work. What am I doing wrong?
Thanks.
Thanks.
' {$STAMP BS2} ' {$PBASIC 2.5} D_Set VAR Word Flag VAR Bit MoveTo CON 2 ClrRt CON 11 pb1 PIN 2 pb2 PIN 3 D_SET = 70 DO DEBUG MoveTo, 0, 1 DEBUG "Defalt Setpoint... " DEBUG DEC2 (D_Set ), CR GOSUB PB LOOP PB: IF (pb2 = 0) THEN Flag = 1 ENDIF IF (pb2 = 0) AND (Flag = 1) THEN D_Set = D_Set - 1 Flag = 0 ENDIF IF (pb1 = 0) THEN Flag = 1 ENDIF IF (pb1 = 1) AND (Flag = 1) THEN D_Set = D_Set + 1 Flag = 0 ENDIF RETURN
Comments
Second, I'd add more constants: "IF (pb2 = PRESSED) THEN" is more comprehensible than "IF (pb2 = 0) THEN"
Third, it looks like you are using two inputs to read one switch? Or two switches? (This is where comments are invaluable.)
--Rich