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:
Code:# define SWITCH_PIN 25
# define LED 48//on board led
int setupcounter;
int variable_0=0;
int variable_1=0;
void setup()
{
pinMode(SWITCH_PIN, INPUT);
variable_0=0;
variable_1=0;
setupcounter=1;
Serial.begin(9600);
loop();
}
void loop()
{
Switch();
delayMicroseconds(1);
}
void Switch()
{
if(digitalRead(SWITCH_PIN)==HIGH)//should run the program
{
setupcounter=0;
digitalWrite(LED,LOW);
Run();
}
else
{
if (setupcounter==0)//reset!
{
setup();
}
else//wait for the switch to be flipped "on"
{
digitalWrite(LED,HIGH);
delay(1);
}
}
}
void Run()
{
Serial.print("the program is running");
variable_0=253;
variable_1++;
delay(1000);
}
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
Titus
(moderator of this forum w00t!)
Edit: 100e post!!!