Wiring Forum
Other questions >> Other Wiring questions >> Program switch?

Message started by Titus on 08/01/08 at 19:06:08

Title: Program switch?
Post by Titus on 08/01/08 at 19:06:08
As part of our robot competitions( 2 vs 2 soccer) there is a kickoff.
We have seen a lot of robot's starting after a few seconds in stead of responding immediatly.
This is like the 7 second delay with wiring.

Now I thought I solved it, although it wasn't perfect.
What I did was:

I mounted a switch(see diagrams on the example page) on pin 25.
When the switch was "off"  I wanted the program to reset all variables etc once and then wait for the switch to be flipped to "on".
When the switch was flipped to "on", the program started running, and checking if the switch was already flipped to "off".

My code for that was:

# define SWITCH_PIN 25
# define LED 48//on board led

int setupcounter;
int variable_0=0;
int variable_1=0;

void setup()




void loop()

void Switch()
 if(digitalRead(SWITCH_PIN)==HIGH)//should run the program
   if (setupcounter==0)//reset!
   else//wait for the switch to be flipped "on"

void Run()
Serial.print("the program is running");


This seemed to work quite smooth, until I found out that the delay in void Run() caused the program to finish the delay time, and then the program would notice the switch being flipped to "off".

-Is there a better way to check the Switch's status?

Aswell I was scared about the (micro)delays in void loop() and void Switch()
Deleting them would cause wiring to overload?

Is this a correct and fail proof way to add a program switch to wiring? Or should I make an adjustment to the program.
I''m open for other suggestions on how to do this aswell.

-There is no way for 2 things to be checked simultaniously? like parallel tasks?

Thanks for your help

(moderator of this forum w00t!)

Edit: 100e post!!!

Title: Re: Program switch?
Post by Vaccumdiode2 on 08/05/08 at 15:55:09
Hello Titus,
                 I would check the switch more often, with a simple if/then.

If (Digitalread(SWITCH_PIN) == LOW)
          I'm not sure if this will slow you down too much but if you put it before your delay and shorten your delay you could come out alright.

          The other thought I had was to put it on an External Interrupts pin.

 attachInterrupt(0, Switch, LOW); // set Switch to be called everytime
                                 // interrupt 0 is generated (everytime the pin gets LOW

          That may work the best for you.  But, I'm not sure if you are already using all of the Interrupts currently in the rest of your program.

           I hope it helps

Rich  ;)

Title: Re: Program switch?
Post by Titus on 08/06/08 at 08:25:46
That's a great idea,

But does the program continue when the pin goes high again, since I want to reset my variables after that?


Title: Re: Program switch?
Post by Vaccumdiode2 on 08/06/08 at 15:07:11
          It should.  it calls out your Subroutine "SWITCH" and it should follow the program from there.  I have not tried it but from what I have read it should work that way.  
          Keep me posted on it.  Also what type of communication are you using for your soccer bots?  Zigbee maybe?  

Well have fun!

Rich ;)

Title: Re: Program switch?
Post by Titus on 08/06/08 at 16:23:14
Going to dig in that, thanks,

Read the CC2500 topic in tangling computing:P That thing is a nice piece of "art". Though we have no clue how to use it:P

Off topic: Did you read my PM?

Title: Re: Program switch?
Post by Vaccumdiode2 on 08/08/08 at 15:29:45
              You know the old saying "What goes around comes around!"  Well it hit me in a possitive way.  Help you out gave me a great Idea for my line follower to simplify it.  I can attach an interrupt and then after I turn then I can detach it.  and when the interrupts are not kicking in I can run the bot foreward.  Do you think it will work?  Well I'll Try it and Let you know.  I need to finish the motor /sensor board this weekend and I will try it after I test the board.  

Thank you

Title: Re: Program switch?
Post by Titus on 08/08/08 at 16:55:34
could work, will work it think,
but if you want a smooth line follower, use analog value's. They are accurate. And external interupts are digital.
you could make a comperator circuit to calibrate you "high" value, but I would recommend using analog sensors(like the wiring diagram of the photoresistor(LDR))

Title: Re: Program switch?
Post by Vaccumdiode2 on 08/08/08 at 17:20:20
           When I get the hard ware together I can try out all kinds of things.  But I think your right about the analog being a smother operation.  
            The way I was going to do the digital interrupt program was use small direction changes and after each change clear the variables and move forward a little.    If I make the program simple enough I was hoping to loop through it at high rate and get my smoth operation that way.  Just sharing my thoughs.  either way it will be great to start play with franken Tank Bot.  I hope to use the same platform for more advance compatitions.

Thank you for the help, encourgement and opinions.


Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.