Digital input trouble

ok guys, building my first picaxe robot and I have a question about the switch I hooked up.

I have a switch wired to digital input 7 and V1 and this is my code

main:
if pin7 = 0 then foreward
goto main

foreward:
low 4 high 5
high 6 low 7
goto main

for some reason when the switch is pressed or let go nothing happpens.

Any ideas why it is not working?

forgot something
I forgot to tell you I am using a picaxe 28x1

try this

main:
if pin7 = 0 then foreward
goto main

foreward:
low 4: high 5: high 6: low 7: pause 100

goto main

also, are you sure yourswitch is connected properly, and to the right pin?

i’ve found that it’s good to have an LED program going as well, so you can see that your chip is still operating

thanks, but no luck
Alright I tried the code and the same thing is happenning. The only difference is that now when I first connect the picaxe to batteries the switch works once and then never works again. I think it has something to do with where I placed the goto commands.

There is no off…
I assume the low: high : low stuff is a motor controller. -Doesn’t matter. Look at the loop -sure, the button turns it “on” but from there, it just stays on! There is nothing in your code to turn it off! Add some pause(s) and stick in a “turn it off” code up with the “if button” stuff.

Forward!

"Foreward"

"Forward"

It’s doing what you tell it.
THe switch is connected between digital input 7 and V1, correct? So pin7 will never be low, and the foreward/forward/fourward code will never be executed. Inputs float high, and when the switch is depressed connecting to V1, which is probably +5 volts or so, guarantees it will be high. So you need to disconnect the switch from V1, and reconnect it to ground, then your code should work. (0 = low. 0 volts)

thanks

Ok, ctc i tried the pauses and the stuff you told me and it still doesn’t work. Robologist I think you may be right, and I will try connecting the wire connected to V1 to ground later today.

this is the code I am currently trying with the switch connected to V1( with wrong spelling of forward)

main:
low 4 low 5 low 6 low 7
if pin7 = 1 then fourward
if pin7 = 0 then main
fourward:
high 4 low 5 low 6 high 7 pause 5000

goto main

By the way ctc the reason I had it written as “foreward” instead of forward is because it registers forward as a command and gives me a syntax error :slight_smile:

what kind of switches?

i had a problem figuring out my switches at first. are yours like these?

With those, the switch would close a circuit to ground when pushed, so the picaxe wasn’t getting any power. It was essentially a reset button. So I figured out that the pole closest to the “hinge” connects to V1, and the middle one connects to your input. Leave the ground alone. Of course, that only applies if you’re using the same switches.

those are the switches
Those are the switches I am using. Only, I am using the switch to make so the robot doesn’t fall off tables and stuff. I know my code doesn’t do that right now, but I am just testing to see if I can get the switch to work.

YAY!

Well I got it to work and not fall off tables! Here is the final code I used:

main:
high 4 low 5 low 6 high 7
if pin7 = 0 then backwurds
if pin7 = 1 then main
backwurds:
low 4 high 5 high 6 low 7 pause 2000
low 4 high 5 low 6 high 7 pause 1700
goto main

( And yes I did spell backwards wrong on purpose :slight_smile: )

highs lows pull-ups pull-downs
I finally checked the PICAxe Electronic Interfacing Manual, and on page 25 there are a couple of circuits to use with switches, for an “if test” of either a high or a low. In the case of testing for a low, they have a pull up resistor and an input resistor, with the switch connected to ground, simlar but not quite as I had stated. The pull-up resisotr ensures the pin is high, not just depnding on the internal pull-ups of the PIC input pins, and the input resistor protects from any possible over-current. The check for high circuit is similar, with a pull-down resistor to make the pin low, another cirrnet liming input, and a switch to high this time. These are both more robust circuits than connecting the input to the switch and the switch then to ground, to make the input low when the switch is pushed. Internal pull-ups of the micros usually work and I’ve used them in the past, but wiring the resistors in is better.

Glad it’s working, hope to
Glad it’s working, hope to see a video soon!

Where should I post the video?
Should I post the video on the blog or this post?

Blog! :slight_smile:
Blog! :slight_smile:

Thanks
Ok thanks to everyone who helped, and I just made the video and uploaded it to youtube. Now I am just waiting for youtube to upload and then I will make a blog post