help with debounce

Hi
I am having trouble making a bit of code to debounce an input switch
could some kind person please give me an example of how to do this please.
I understand that you have to read an input,
put it into a variable,
wait 20ms,
re read the input,
and compare the 2 results.

The problem i have is no matter what i try i get compiler errors or the output that is controlled by the input result does not switch.

symbol switchenable = b1
symbol direction = b0
symbol clockwise = 1
symbol anticlockwise = 0

start0:

main:
input c.4
readadc c.4, direction
pause 20
readadc c.4, switchenable
if switchenable = direction then label3
switchenable = 0
goto main



label3:


select direction
case clockwise low c.1
case anticlockwise high c.1
endselect
goto main

start1:

do

high c.2
pauseus 1
low c.2
pauseus 1

loop

I think the problem lies around the variable that the result is placed into, but I cant see what i need to do

thanks
 

grim_reaper

Senior Member
You're reading a byte into 'direction' - the ADC input value - then under label3: you're doing a select case to determine if it's 0 or 1. Unless your analogue input is very digital, it's not likely to be a 0 or 1 very often!
 

grim_reaper

Senior Member
Without a circuit diagram, it's not possible to give a precise answer. However, if your switch is passing in either 0v or VDD (5v?) to the AXE input, you'll get a reading of either 0 or 255. [And that's in a perfect world, you may get 254, 253, etc.]. It's best to do a bit of debugging to see what it's actually doing, and help you get your head round it.
 

hippy

Ex-Staff (retired)
its just a simple on off switch, I thought that would be 1 or 0 no?
Yes; when read as a digital input.

With a switch wired as described in PICAXE Manual 3 this might do what you require -

Code:
main:
input c.4
direction = pinC.4
pause 20
switchenable = pinC.4
if switchenable = direction then label3
goto main
 
Top