I would like to ask a question regarding a blinking led sketch i am trying. I am new to the arduino uno and the C language. I am trying to expand a little on the blinking led sketch from the Arduino web site.
OK
What I am trying to do is get 2 leds to work independently of each other. For eg, green flash 300 milli on/off and the red to flash 1 sec on/off without interfering with each other.
My sketch so far is:
int pin12 = 12; // green led
int pin11 = 11; // red led
int timer = 50;
void setup() {
pinMode(pin12, OUTPUT); // green
pinMode(pin11, OUTPUT); // red
}
Nothing to do with your original question, but assigning the value of 12 to a variable called pin12 does not help much with reading your code. You may as well not bother. If, however, you were to name the variables (or even better make them consts) green and red it would be easier to understand exactly what was going on later.
Donmerrick:
Thank you very much. works a treat and now just need to learn from the code.
You're very welcome! Let us know if you have questions on the code. Some suggestions:
Study the BlinkWithoutDelay example sketch first which blinks a single LED. Once that is well understood, move on to two LEDs. The main aim is to avoid calling the delay() function altogether.
While I strongly recommend understanding BlinkWithoutDelay first, also be aware that there are libraries that can simplify these sorts of tasks. The example below uses one of them. I think there are more in the playground.