🔒 Closed Mga lods pahelp po arduino coding

Status
Not open for further replies.

Vermouth the Gin

✌𝓝𝓮𝓿𝓮𝓻 𝓑𝓮𝓽𝓽𝓮𝓻 ✌
Mga lods pahelp po about arduino coding,
Subject namin microprocessor kaka start ko lng po sa arduino
Ni study ko na po din to kasi para sa future programing ng thesis ko

Pahelp po paano mag shorten ng code pero same output result lng in po

Maraming Salamat po sa help!

ito po yung code

int ledPin = (9,10);
void setup(){
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop(){

digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);
delay(500);
digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);
delay(500);
digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);
delay(500);
digitalWrite(10, HIGH);
delay(500);
digitalWrite(10, LOW);
delay(500);
digitalWrite(10, HIGH);
delay(500);
digitalWrite(10, LOW);
delay(500); digitalWrite(10, HIGH);
delay(500);
digitalWrite(10, LOW);
delay(500); digitalWrite(10, HIGH);
delay(500);
digitalWrite(10, LOW);
delay(500);

}

ardeniu.webp ardeniu1.webp
 
Hi! I can see that your code is controlling two LEDs connected to pins 9 and 10 of your Arduino board. To shorten your code, you can use a loop to repeat the same code for both LEDs. Here's an example:

Code:
int ledPins[] = {9, 10}; // declare an array with the LED pins

void setup() {
  // set the LED pins as outputs
  for (int i = 0; i < 2; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
  // loop through each LED and blink it 3 times
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
      digitalWrite(ledPins[i], HIGH);
      delay(500);
      digitalWrite(ledPins[i], LOW);
      delay(500);
    }
  }
}

In this example, we use an array ledPins to store the LED pins, and a for loop to set them as outputs in the setup() function. Then we use two nested for loops in the loop() function to loop through each LED and blink it three times, with a delay of 500ms between each blink.

I hope this helps! Let me know if you have any questions.
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 433
    Views
  • 2
    Participants
Last reply from:
Vermouth the Gin

Trending Topics

Online now

Members online
666
Guests online
1,314
Total visitors
1,980

Forum statistics

Threads
2,273,541
Posts
28,950,272
Members
1,235,809
Latest member
NoritoshiKamoo
Back
Top