Go Down

### Topic: Some helps with some code. (Read 849 times)previous topic - next topic

#### crimelobster

##### Aug 08, 2012, 03:09 pm
I would like to know how to get 4 leds to blink all at the same time.
Uno rev 3
windows seven if it helps.

#### AWOL

#1
##### Aug 08, 2012, 03:18 pm
Quote
I would like to know how to get 4 leds to blink all at the same time.

Exactly at the same time, or would it not matter if they were a few microseconds off?

Can you make one LED blink?
Four isn't much harder.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### florinc

#2
##### Aug 09, 2012, 10:14 pm
Quote
how to get 4 leds to blink all at the same time

If you put 4 red LEDs in series on pin 13, you may be able to use the Blink sketch coming with Arduino IDE.

#### JoeN

#3
##### Aug 09, 2012, 10:36 pm

Quote
how to get 4 leds to blink all at the same time

If you put 4 red LEDs in series on pin 13, you may be able to use the Blink sketch coming with Arduino IDE.

The typical voltage drop of a red LED is 1.8 volts so that will probably not work.  If you put them in parallel that might cause uneven brightness, but they should light up.   The most complex way would be to connect an appropriate resistor to each of four pins (say 330 ohm for 15mA) and each resistor to the anode of each LED and the cathode of each LED back to the ground on the Arduino.  Then push those 4 pins to 1 to turn the LEDs on and then to 0 to turn them off.  The arduino blink sketch:

void loop() {
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);               // wait for a second
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
delay(1000);               // wait for a second
}

would be modified to something like this:

void loop() {
digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
digitalWrite(led2, HIGH);   // turn the LED on (HIGH is the voltage level)
digitalWrite(led3, HIGH);   // turn the LED on (HIGH is the voltage level)
digitalWrite(led4, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);               // wait for a second
digitalWrite(led1, LOW);    // turn the LED off by making the voltage LOW
digitalWrite(led2, LOW);    // turn the LED off by making the voltage LOW
digitalWrite(led3, LOW);    // turn the LED off by making the voltage LOW
digitalWrite(led4, LOW);    // turn the LED off by making the voltage LOW
delay(1000);               // wait for a second
}

where led1, led2, led3, led4 are the pins you have chosen for your resistor/LED combinations
I will never ask you to do anything that I wouldn't do myself.

#### florinc

#4
##### Aug 10, 2012, 02:52 am
That's not "all at the same time" though

#### JoeN

#5
##### Aug 10, 2012, 03:10 am

That's not "all at the same time" though

Close enough for government work.

I leave it to the student as an exercise to turn them all on at the exact same time using port masking.   XD
I will never ask you to do anything that I wouldn't do myself.

Go Up