Go Down

Topic: How do I write code for INDIVIDUAL LED's? (Read 81 times) previous topic - next topic


I apologize in advance...this may be a very basic question.  I know VERY little about electrical components and bought the Arduino Micro without even knowing what a board is or does!  Yet, in the last 24 hours I have completed and learned a lot of great information!  But I am stumped on what may be considered by most of you as something very simple.  Below is the code I used to test an LED on pin 13.

int led = 13;
void setup() {


void loop() {
  digitalWrite(led, HIGH);
  digitalWrite(led, LOW);


Easy enough.  But, what I am trying to figure out is how to run the above code on pin 13, while running a different code on pin 12.  Say for example, while pin 13 is blinking (on and off every second), pin 12 will turn on after five seconds, and turn off again after 10 seconds.

Any help would be greatly appreciated.  Thank you!

jack wp


Using millis()

Take a look at BlinkWithoutDelay

Also this thread (I think this is the right one to be linking people to?). This is a very common topic of discussion here, because the early examples throw delay() around - when delay is almost never usable in a practical sketch because it blocks (when something is said to "block", that means the program sits there until it completes)

ATtiny core for 841+1634+828 and x4/x5/x61/x7/x8 series Board Manager:
ATtiny 841/1634/828/88/861/167 breakouts, mosfets, touch sensors and prototyping board in my store http://tindie.com/stores/DrAzzy


Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

jack wp

"when delay is almost never usable in a practical sketch because it blocks "
I agree, it is almost never usable "inside the loop() function.
But, inside the setup() function, it is fine to use.

And if the loop() function is only doing one think, it is ok to use delay() there. delay() becomes a problem when there are more than one process going on within the loop() function, and should not be used in that case. Even then there are exceptions (you may use a delay(1) or 2, in specific situations, But delay(1000) would normally not be advisable.

Go Up