BASIC4MCU | 질문게시판 | 아두이노 멀티태스킹 질문합니다.
페이지 정보
작성자 ffnui 작성일2018-06-14 16:24 조회45,361회 댓글8건본문
올려주신 예제로 해보있는데 잘안돼서 질문드립니다.
아두이노 레오나르도 버전을 사용하고있습니다.
#include <TimerOne.h>
const int pin_LED0 = 5;
const int pin_LED1 = 6;
const int pin_LED2 = 8;
const int pin_LED3 = 9;
const int pin_LED4 = 10;
const int pin_LED5 = 11;
const int pin_LED6 = 12;
const int pin_LED7 = 13;
byte led_pinlist[14]={5,6,8,9,10,11,12,13,12,11,10,9,8,6,};
int pin_SW1=3;
int dir=0,index=0,cnt=0,flag=0;
void setup(){
pinMode(pin_SW1,INPUT);
pinMode(pin_LED0, OUTPUT);
pinMode(pin_LED1, OUTPUT);
pinMode(pin_LED2, OUTPUT);
pinMode(pin_LED3, OUTPUT);
pinMode(pin_LED4, OUTPUT);
pinMode(pin_LED5, OUTPUT);
pinMode(pin_LED6, OUTPUT);
pinMode(pin_LED7, OUTPUT);
Timer1.initialize(1000000);
Timer1.attachInterrupt(blinky);
Serial.begin(9600);
// pinMode(10,INPUT_PULLUP);
}
void loop(){
uint8_t SW_1_data;
SW1_data = digitalRead(pin_SW1);// 스위치1번을 눌렀을때 점멸 진행방향이 바뀌고싶습니다
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; }
//
for(int i=0;i<14;i++)pinMode(led_pin[i],OUTPUT);
digitalWrite(led_table[index],HIGH);
}
댓글 8
조회수 45,361ffnui님의 댓글
ffnui 작성일
올려주신 예제에서 pin번호만 바꾸어서 돌려봤는데
#include <TimerOne.h>
^
compilation terminated.
exit status 1
보드 Arduino Leonardo 컴파일 에러.
라는 에러도 뜹니다.
master님의 댓글
master 작성일TimerOne 라이브러리 설치하세요
master님의 댓글
master 작성일
#include <TimerOne.h>
const int pin_LED0=5;
const int pin_LED1=6;
const int pin_LED2=8;
const int pin_LED3=9;
const int pin_LED4=10;
const int pin_LED5=11;
const int pin_LED6=12;
const int pin_LED7=13;
byte led_pinlist[14]={ 5,6,8,9,10,11,12,13,12,11,10,9,8,6,};
int pin_SW1=3;
int dir=0,index=0,cnt=0,flag=0;
void setup(){
pinMode(pin_SW1,INPUT);
pinMode(pin_LED0,OUTPUT);
pinMode(pin_LED1,OUTPUT);
pinMode(pin_LED2,OUTPUT);
pinMode(pin_LED3,OUTPUT);
pinMode(pin_LED4,OUTPUT);
pinMode(pin_LED5,OUTPUT);
pinMode(pin_LED6,OUTPUT);
pinMode(pin_LED7,OUTPUT);
Timer1.initialize(1000000);
Timer1.attachInterrupt(blinky);
Serial.begin(9600);
// pinMode(10,INPUT_PULLUP);
}
//
void loop(){
if(digitalRead(pin_SW1)){ // 스위치1번을 눌렀을때 점멸 진행방향이 바뀌고싶습니다
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; }
//
for(int i=0; i<14; i++)pinMode(led_pin[i],OUTPUT);
digitalWrite(led_table[index],HIGH);
}
ffnui님의 댓글
ffnui 작성일
다운로드해서 라이브러리에 적용후 돌려봤습니다.
sketch_jun14a:42: error: 'led_pin' was not declared in this scope
for(int i=0; i<14; i++)pinMode(led_pin[i],OUTPUT);
^
sketch_jun14a:43: error: 'led_table' was not declared in this scope
digitalWrite(led_table[index],HIGH);
^
exit status 1
'led_pin' was not declared in this scope
에러가 납니다.
제가 주석처리한 // pinMode(10,INPUT_PULLUP); 코드부분은 필요없나요?
master님의 댓글
master 작성일
led_table[index]
led_pinlist[14]
배열 이름을 맞춰주세요
ffnui님의 댓글
ffnui 작성일
#include <TimerOne.h>
byte led_pin[8]={5,6,8,9,10,11,12,13};
byte led_arr[14]={ 5,6,8,9,10,11,12,13,12,11,10,9,8,6,};
int pin_SW1=3;
int dir=0,index=0,cnt=0,flag=0;
void setup(){
pinMode(pin_SW1,INPUT);
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(pin_SW1)){ // 스위치1번을 눌렀을때 점멸 진행방향이 바뀌고싶습니다
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; }
//
for(int i=0; i<14; i++)
pinMode(led_pin[i],OUTPUT);
digitalWrite(led_arr[index],HIGH);
}
배열이름도 맞춘거같은데 ㅠㅠㅠㅠ
C:sketch_jun14a\sketch_jun14a.ino: In function 'blinky()':
C:\sketch_jun14a\sketch_jun14a.ino:28:28: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations]
pinMode(led_pin[i],OUTPUT);
^
C:\\sketch_jun14a\sketch_jun14a.ino:27:3: note: containing loop
for(int i=0; i<14; i++)
^
C:\sketch_jun14a\sketch_jun14a.ino: In function 'blinky':
C:\Users\Documents\sketch_jun14a\sketch_jun14a.ino:28:28: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations]
pinMode(led_pin[i],OUTPUT);
^
C:\Users\404\Documents\20141502\sketch_jun14a\sketch_jun14a.ino:27:3: note: containing loop
for(int i=0; i<14; i++)
master님의 댓글
master 작성일
#include <TimerOne.h>
const int pin_LED0=5;
const int pin_LED1=6;
const int pin_LED2=8;
const int pin_LED3=9;
const int pin_LED4=10;
const int pin_LED5=11;
const int pin_LED6=12;
const int pin_LED7=13;
byte led_pinlist[14]={ 5,6,8,9,10,11,12,13,12,11,10,9,8,6,};
int pin_SW1=3;
int dir=0,index=0,cnt=0,flag=0;
void setup(){
pinMode(pin_SW1,INPUT);
pinMode(pin_LED0,OUTPUT);
pinMode(pin_LED1,OUTPUT);
pinMode(pin_LED2,OUTPUT);
pinMode(pin_LED3,OUTPUT);
pinMode(pin_LED4,OUTPUT);
pinMode(pin_LED5,OUTPUT);
pinMode(pin_LED6,OUTPUT);
pinMode(pin_LED7,OUTPUT);
Timer1.initialize(1000000);
Timer1.attachInterrupt(blinky);
Serial.begin(9600);
// pinMode(10,INPUT_PULLUP);
}
//
void loop(){
if(digitalRead(pin_SW1)){ // 스위치1번을 눌렀을때 점멸 진행방향이 바뀌고싶습니다
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; }
//
for(int i=0; i<14; i++)pinMode(led_pinlist[i],OUTPUT);
digitalWrite(led_pinlist[index],HIGH);
}
ffnui님의 댓글
ffnui 작성일감사합니다!!!