Pages: [1]   Go Down
Author Topic: Some helps with some code.  (Read 490 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

More Cowbell
Offline Offline
Edison Member
*
Karma: 11
Posts: 1025
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Vexatious Sampler

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

More Cowbell
Offline Offline
Edison Member
*
Karma: 11
Posts: 1025
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.   smiley-lol
Logged

Vexatious Sampler

Pages: [1]   Go Up
Jump to: