|
316
|
Using Arduino / Programming Questions / Re: bootloader delay
|
on: April 15, 2013, 09:58:25 am
|
as accurate as possible. i'm competing in a sumo bot competition and there is a five second delay before starting. if i start too early i'm disqualified. if i start a second late the other bot has a jump on me.
How accurately, and by what method, is the delay being measured in the competition ?
|
|
|
|
|
319
|
Using Arduino / Programming Questions / Re: Button Sequence help
|
on: April 15, 2013, 09:17:26 am
|
|
The flowchart is a good start. Looking at it I can see why you had a problem describing what you want to do.
What I would do next is to use the chart to break the sequence into a number of states that the program might be in. For instance, waiting for the button 1 to be pressed to start the sequence could be state 1, waiting for button 2 could be state 2, the first 2 second delay could be state 3 etc. Then you write down what has to happen to get out of a state, such as pressing a button or a delay ending, and the state that the program should move to when the change happens.
Now, how to program it. My suggestion would be to use switch/case with the switch variable being the state and the cases being the current states. For each state, test for the action(s) required to exit the state, carry out the actions and change the state variable to the state you are moving to. Put this in the loop() function and the program will continually monitor the state and look for actions being taken.
Incidentally, I can see some anomalies in your flowchart or maybe some explanation is needed. After button 2 has been pressed near the start you have a test for whether button 2 has been pressed. Is that a second press or the original one ?
|
|
|
|
|
320
|
Using Arduino / Programming Questions / Re: Can serial receive a byte and send it immediately?
|
on: April 15, 2013, 05:40:01 am
|
Am I reading that right ? I hope not, but it wouldn't be the first time I got some code wrong. Here it is with the comments I probably should have included while (1) { // do forever while (Serial1.available() < 1) {}; // wait for at least 1 character to become available Serial1.print(Serial1.read(), HEX); // read and transmit the character } I also added the braces after the empty while busy loop, I normally do that to highlight that the loop does nothing. ______ Rob Ah, that makes more sense and I can see that I was wrong
|
|
|
|
|
321
|
Using Arduino / Programming Questions / Re: bootloader delay
|
on: April 15, 2013, 04:26:26 am
|
|
I wouldn't bother messing with the bootloader. As has been suggested, start with delay(5000) at the end of setup(), turn on an LED at the end of the delay() and tweak the value to make the total startup delay exactly what you want. How accurate does the 5 second delay have to be ?
|
|
|
|
|
325
|
Using Arduino / Programming Questions / Re: Handling interrupts properly when using multiple inputs
|
on: April 15, 2013, 01:37:38 am
|
|
Calling the loop() function from inside an ISR seems a bizarre thing to do, as does doing 3 analogWrites which take a comparatively long time to execute. The usual technique when using an ISR is for it to set a variable to indicate that it has been triggered and for the value of the variable to be acted upon in the main program.
This is only possible if the delay() function is not used in the main program because this blocks execution of other code until the delay() is complete and your code is full of them. Consider using millis() as a timer using the technique used in the BlinkWithoutDelay example program.
|
|
|
|
|