준비물
아두이노 칩 or 아트메가 168 외 아트메가들
아두이노 프로그램
LED 12개
버튼 1개
10k 저항 1개
점퍼케이블


결과





회로구성
2~13번 디지털핀에 LED
16번 핀에 버튼과 10k 저항 연결



아두이노 코드

int pinArray[] = {2,3,4,5,6,7,8,9,10,11,12,13};
int count = 0;
int timer = 100;
int switchIn = 16;
int cons=0;


void setup(){
  for (count=0;count<12;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
  pinMode(switchIn, INPUT);
}
void loop() {
  for (count=cons; count<12; count++) {
    if (digitalRead(switchIn)==1){
      cons = count;
      if(cons == 11){
        cons = 0;
      }
      light(count);
    }
  }
  for (count=cons; count>=0; count--) {
    if (digitalRead(switchIn)==0){
      cons = count;
      if(cons == 0){
        cons = 11;
      }
      light(count);
    }
  }


int light(int x){
    digitalWrite(pinArray[x], HIGH);
 
    for (int i = 0; i < x; i++){
        digitalWrite(pinArray[i], LOW);
    }   
    for (int j = 11; j > x; j--){
        digitalWrite(pinArray[j], LOW);
    }
    delay(timer); 
}


// 더짧은 코드나 수정이 필요한 부분은 언제든 코맨드 부탁드립니다 ^^

'S artworks > Arduino' 카테고리의 다른 글

Interaction Light - [ awake ]  (1) 2011.12.16
아두이노 - 버튼을 눌러 LED 제어하기 . 01  (0) 2011.04.05

+ Recent posts