how to blink multiple led in c

Mar 24, 2021 at 4:56pm
hi to all
i am new in programming. i write a code in c. but problem how to multiple led blink in c

1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * Blink - makes a single LED blink on and off
 */

void setup() {
  pinMode(13, OUTPUT); // pin 13 - change value if you have LED on diff pin
}

void loop() {
  digitalWrite(13, HIGH);  // set pin 13 to high voltage, turning LED on
  delay(1000);             // wait 1000 milliseconds, or one second.
  digitalWrite(13, LOW);   // set pin 13 to low voltage, or zero. LED off.
  delay(1000);             //wait one second before starting the loop again. 




https://projectiot123.com/2019/01/04/arduino-library-for-proteus-simulation/
Last edited on Mar 25, 2021 at 9:30am
Mar 24, 2021 at 5:55pm
> pin 13 - change value if you have LED on diff pin
So can't you do this?

1
2
3
4
5
void setup() {
  pinMode(13, OUTPUT); // pin 13 - change value if you have LED on diff pin
  pinMode(12, OUTPUT); // OMG - pin 12 also has an LED
}

Mar 24, 2021 at 6:01pm
thanks your reply
but how i blink 6 leds in different pattern i have arduino uno and starter kit
Mar 24, 2021 at 6:20pm
<80s-kitsch>
Maybe you need the right KITT
https://tutorial45.com/arduino-led-project-knight-rider/
</80s-kitsch>

Mar 24, 2021 at 8:40pm
The key is that the loop runs at a high rate. Each time through the loop, you decide which LEDs (if any) must be toggled.
1
2
3
4
5
6
void loop() {
  if (time to toggle LED1) toggleLED1();
  if (time to toggle LED2) toggleLED2();
  ...
  delay(50);  // Delay 50 ms
};


You should probably encode whether to toggle the LEDs in some data. Maybe there's an array associated with each LED that says whether it goes on or off:
char arr1[20] = "01001100011100001111";
Then each time through the loop, in increment a counter (reset to zero when you hit the end of the array) and turn the LED on or off depending on whether the array value is '0' or '1'.
Mar 25, 2021 at 9:30am
ok thanks. i will try
Topic archived. No new replies allowed.