[Arduino] How to make LED blinking
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
int timer = 50; // The higher the number, the slower the timing.
// the setup routine runs once when you press reset:
void setup() {
for (int i = 2; i <= 11; i++) {
// initialize the digital pin as an output.
pinMode(i, OUTPUT);
}
}
// the loop routine runs over and over again forever:
void loop() {
for (int thisPin = 2; thisPin <= 11; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
for (int thisPin = 11; thisPin >= 2; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
// Reference:
// 1. For Loop (aka The Knight Rider)
0 意見:
張貼留言