Go Down

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

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

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.

florinc

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


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 have only come here seeking knowledge. Things they would not teach me of in college.

florinc

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

JoeN


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 have only come here seeking knowledge. Things they would not teach me of in college.

Go Up