Switch, trigger and code question

DanoNJ

New Member
As I have stated prior, I have no code experience. I can not seem to get a switch and a trigger to work at all.

All in all, the code seems to work for me, that is until I inserted “if __then” statements. The main body will still work, but the switches has no influence on the code.

Here is the lay out:
C.4 will be connected to the main start button. So, I want the system to be dead until that button is pressed. I believe I currently have the pin pulled low until the button is hit.
Currently when I turn on power, the prop will begin to run. The switch has no effect.

Secondly the dump rod does not run at all.

What I need to happen is that a second switch will be triggered to turn off the dump rod.
That switch will be connected to C.3.
Again, currently pulled low.

I used the diagram in Manual 3 for wiring the switches which are micros. I also saw this page which talks about different code to use - http://www.picaxe.com/Circuit-Creator/Switches/Microswitch/

Very confused...

I added a picture of the prop - maybe it will help understand what I'm doing

Thanks so much for the help!
Code:
[color=Navy]#picaxe [/color][color=Black]14m2[/color]

[color=Blue]symbol sugar [/color][color=DarkCyan]= [/color][color=Blue]b.1
symbol stripes [/color][color=DarkCyan]= [/color][color=Blue]b.2
symbol gears [/color][color=DarkCyan]= [/color][color=Blue]b.3
symbol pump [/color][color=DarkCyan]= [/color][color=Blue]b.4
symbol rod [/color][color=DarkCyan]= [/color][color=Blue]b.5

servo b.1[/color][color=Black], [/color][color=Navy]150[/color]
[color=Blue]servo b.2[/color][color=Black], [/color][color=Navy]150[/color]
[color=Blue]servo b.3[/color][color=Black], [/color][color=Navy]150[/color]
[color=Blue]servo b.4[/color][color=Black], [/color][color=Navy]149[/color]
[color=Blue]servo b.5[/color][color=Black], [/color][color=Navy]150[/color]


[color=Blue]input[/color][color=Black]: [/color][color=Blue]c.4 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Blue]input[/color][color=Black]: [/color][color=Blue]c.4 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]


[color=Black]main:[/color]

[color=Blue]if [/color][color=Purple]b4 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then start1:  [/color][color=Green]'starting switch pushed[/color]

[color=Blue]start1:                 [/color][color=Green]'main program[/color]

[color=Blue]servopos sugar[/color][color=Black], [/color][color=Navy]150     [/color][color=Green]'left elf dump sequence[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]servopos sugar[/color][color=Black], [/color][color=Navy]70[/color]
[color=Blue]pause [/color][color=Navy]2000[/color]
[color=Blue]servopos sugar[/color][color=Black], [/color][color=Navy]150[/color]
[color=Blue]pause [/color][color=Navy]2000[/color]
[color=Blue]servopos sugar[/color][color=Black], [/color][color=Navy]70[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]servopos sugar[/color][color=Black], [/color][color=Navy]150[/color]
[color=Blue]pause [/color][color=Navy]3000[/color]

[color=Blue]servopos stripes[/color][color=Black], [/color][color=Navy]150     [/color][color=Green]'right elf dump sequece[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]servopos stripes[/color][color=Black], [/color][color=Navy]70[/color]
[color=Blue]pause [/color][color=Navy]2000[/color]
[color=Blue]servopos stripes[/color][color=Black], [/color][color=Navy]150[/color]
[color=Blue]pause [/color][color=Navy]2000[/color]
[color=Blue]servopos stripes[/color][color=Black], [/color][color=Navy]70[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]servopos stripes[/color][color=Black], [/color][color=Navy]150[/color]
[color=Blue]pause [/color][color=Navy]3000[/color]

[color=Blue]servopos gears[/color][color=Black], [/color][color=Navy]155     [/color][color=Green]'start up gears   [/color]
[color=Blue]servopos pump[/color][color=Black], [/color][color=Navy]156      [/color][color=Green]'start up pump[/color]
[color=Blue]pause [/color][color=Navy]5000[/color]

[color=Blue]servopos rod[/color][color=Black], [/color][color=Navy]75        [/color][color=Green]'start up drop rod[/color]

[color=Blue]if [/color][color=Purple]b3 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then start2:  [/color][color=Green]'if microswitch tripped, stop drop rod[/color]

[color=Blue]start2:
servopos rod[/color][color=Black], [/color][color=Navy]150       [/color][color=Green]'drop rod stopped[/color]


[color=Blue]goto [/color][color=Black]main               [/color][color=Green]'hold till button pressed[/color]
 

Attachments

bpowell

Senior Member
Well...here are a few quick observations to get you going...

You're using C.4 and C.3 as INPUT...that's good...but you declare C.4 twice...so check on that.

Then, in your main program, you're saying, "If [variable] b4 = 1 then [goto] start1"...you should be testing for if C.4 = 1, not b4...b4 is just a variable that you haven't assigned a value to yet.

That being said...after the first "if-then"...the program will then "fall into" start1:....so, to prevent that, you should have something like...

main:

do
if c.4 = 1 then gosub start1: (be sure to add a "return" to the end of your START1 routine)
loop

This will keep your program from doing anything until C.4 is high.

Same thing with your "if b3 = 1 then start2:" line...I think you want to test C.3, not B3...

Oh, and you should add a .1uf cap across + and - on the Picaxe....this will keep the chip stable with all those servos pulling power and moving around.

Good luck!
 

techElder

Well-known member
All well and good, but your program doesn't look like you intended it to be a multi-tasking program. You have a problem with labels.

Manual 2, Page 267. Appendix 3 - Reserved Labels
The following labels have special meanings and are reserved for use with that specific purpose only:
interrupt:
start0:, start1:, start2:, start3: start4:, start5:, start6:, start7:
(interrupts - see setint command) (parallel tasks - see restart command)

Also, see Manual 1, page 62 for more explanation.
 
Top