답변 : 아두이노 LED 8개 좌우 쉬프트, 타이머1 1초
페이지 정보
작성자 master 작성일18-06-14 11:05 조회5,453회 댓글0건본문
// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-06-14 오전 11:08:10
// by Ok-Hyun Park
//
#include <TimerOne.h>
//
byte led_pin[ 8]={2,3,4,5,6,7,8,9}; // LED핀번호
byte led_arr[14]={2,3,4,5,6,7,8,9,8,7,6,5,4,3}; // LED 점등순서
//
int dir=0,index=0,cnt=0,flag=0;
//
void setup(){
for(int i=0;i<8;i++)pinMode(led_pin[i],OUTPUT);
Timer1.initialize(1000000);
Timer1.attachInterrupt(blinky);
Serial.begin(9600);
pinMode(10,INPUT_PULLUP);
}
//
void loop(){
if(!digitalRead(10)){
if(flag==0){ flag=1; dir^=1; } // 쉬프트 방향 토글
}
else flag=0;
//
delay(100);
}
//
void blinky(){
if(dir==0){ if(++index>13)index=0; } // 증가
else { if(--index<0)index=13; } // 감소,dir=1
//
for(int i=0;i<14;i++)pinMode(led_pin[i],OUTPUT); // all off
digitalWrite(led_table[index],HIGH); // 해당핀만 on
}
댓글 : 0
조회수 : 5,453
등록된 댓글이 없습니다.