Can someone please tell me how I could make the code below only run for say 5 seconds and then start another sequence of blinks for just the Cross/pin 8 for another 5 seconds before looping back to he beginning?
Or is this impossible when using blink without delay!?
// constants won't change. Used here to
// set pin numbers:
const int OUTER = 7;// the number of the LED pin
const int CROSS = 8;// the number of the LED pin
const int CIRC = 9;// the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(OUTER, OUTPUT);
pinMode(CIRC, OUTPUT);
pinMode(CROSS, OUTPUT);
}
void loop () {
static unsigned long starttime;
static int ledstate = LOW;
if (ledstate == HIGH && millis() - starttime > 200) {
ledstate = LOW;
digitalWrite(OUTER, LOW);
digitalWrite(CIRC, LOW);
digitalWrite(CROSS, LOW);
starttime = millis();
}
else if (ledstate == LOW && millis() - starttime > 200) {
ledstate = HIGH;
digitalWrite(OUTER, HIGH);
digitalWrite(CIRC, HIGH);
digitalWrite(CROSS, HIGH);
starttime = millis();
}
}
This a long thread: http://arduino.cc/forum/index.php/topic,115352.0.html
But you should look at some examples. In the second post of that thread I posted some links. Look at them to see if they can be of use for you.
I could look at your code, but I'm not sure what you want.
To answer your question about blink without delay: anything is possible.
I added another mode and that worked great, however, I tried adding an extra mode but the code does not seem to work now. I have changed the mode module to 3 (#define MODE_MODULO 3) .... is there something different I have to do for more than 2 modes to work?
Paul - What would the solution be instead of using { after an executable on this code?
The issue isn't using a { after an executable statement. It is having another statement on the same line as the {.
There is nothing syntactically wrong with doing that. There is nothing logically wrong with doing that. It just makes your code damned hard to read.
but the code still does not work.
The code does something. You want it to do something. Clearly those two somethings are not the same thing. What either of them is is a mystery, though.
Had a better look at it all this morning and I have it working just nicely now. Thank you again!
Thinking ahead on my project there is something that I am pondering over .... Using the Mode_Module and having the modechangetime set to 5000 works great. But is it possible to have an additional modechangetime at 1000 too so I can make some other LED's blink at a faster rate?
You could do the same with one mode variable but you probably have to define more modes and you have to change what your code is doing. It depends on what you wanna achieve which of the two ways is more appropriate.