BASIC4MCU | 질문게시판 | 답변 : 아두이노 외부인터럽트를 활용하여 밝기를 조절하는데 해결이 되지 않습니다
페이지 정보
작성자 master 작성일2022-12-04 17:08 조회1,067회 댓글1건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=22030
본문
const int pinLED1=11,pinLED2=10,pinLED3=9;
const int pinBtn=2; // Interrupt0
//
volatile int state=0,flag=1;
//
void setup(){
pinMode(pinBtn,INPUT_PULLUP);
attachInterrupt(0,ledControl,RISING);
Serial.begin(9600); Serial.print("srart"); Serial.println(state);
}
//
void loop(){
if(flag){ flag=0;
Serial.print("cur state"); Serial.println(state);
analogWrite(11,state); analogWrite(10,state); analogWrite(9,state);
}
}
//
void ledControl(){
if (state>128)state=128;
else if(state> 0)state= 0;
else state=255;
flag=1;
}
댓글 1
조회수 1,067Ssll님의 댓글
Ssll 작성일감사합니다 덕분에 해결하였습니다