Arduino 배열을 이용한 LED 제어
# ex1
int pinLED[]={3,5,6,9};
int i;
int delay_t = 500;
void setup() {
Serial.begin(9600);
for(i=0; i < 4; i++)
pinMode(pinLED[i], OUTPUT);
}
void loop() {
for(i=0; i < 4; i++) {
digitalWrite(pinLED[i-1], 0);
digitalWrite(pinLED[i], 1);
delay(delay_t);
}
for(i=3; i > 0; i--) {
digitalWrite(pinLED[i], 0);
digitalWrite(pinLED[i-1], 1);
delay(delay_t);
}
}
# ex2
1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
2
3
4
3 4
2 3 4
1 2 3 4
2 3 4
3 4
4
3
2
1
int pinLED[]={3,5,6,9};
int i;
int delay_t = 500;
void setup() {
Serial.begin(9600);
for(i=0; i < 4; i++)
pinMode(pinLED[i], OUTPUT);
}
void loop() {
for(i=0; i <= 3; i++) {
digitalWrite(pinLED[i], 1);
delay(delay_t);
}
for(i=3; i > 0; i--) {
digitalWrite(pinLED[i], 0);
delay(delay_t);
}
for(i=0; i <= 3; i++) {
digitalWrite(pinLED[i], 1);
digitalWrite(pinLED[i-1], 0);
delay(delay_t);
}
for(i=3; i >= 0; i--) {
digitalWrite(pinLED[i], 1);
delay(delay_t);
}
for(i=0; i < 3; i++) {
digitalWrite(pinLED[i], 0);
delay(delay_t);
}
for(i=3; i > 0; i--) {
digitalWrite(pinLED[i], 0);
digitalWrite(pinLED[i-1], 1);
delay(delay_t);
}
}
'IT Tech > Arduino' 카테고리의 다른 글
AppInventor (0) | 2019.03.05 |
---|---|
Arduino Serial LCD-1602 Shield V2.0 (0) | 2019.03.04 |
아두이노 프로젝트 모음 (0) | 2019.03.04 |
Arduino Pin Map (0) | 2019.03.04 |
Secrets of Arduino PWM (0) | 2019.03.04 |