how to blink multiple led in c

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
> 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
}

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

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'.
ok thanks. i will try
Topic archived. No new replies allowed.