Let's Make Robots!

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

if pin7 = 0 then foreward
goto main

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?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
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
Should I post the video on the blog or this post?
Blog! :)

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

high 4 low 5 low 6 high 7
if pin7 = 0 then backwurds
if pin7 = 1 then main
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 :) )

Glad it's working, hope to see a video soon!
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.

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.

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.

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)

low 4 low 5 low 6 low 7
if pin7 = 1 then fourward
if pin7 = 0 then main
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 :)

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)