BASIC4MCU | 질문게시판 | 인터럽트 관련 질문드립니다.. 아두이노 초보입니다
페이지 정보
작성자 peanutbutter 작성일2020-06-25 02:27 조회3,398회 댓글1건본문
아두이노를 시작한지 얼마되지 않았는데 외부 인터럽트를 주는 것을 진행하기가 힘듭니다.
여기서 2번째 스위치로 led 두개에 어떠한 변화라도 주고 싶은데 전혀 변화가 없습니다...
어떻게 해야 두개 led 에 인터럽트를 줄 수 있는지 질문드립니다.
const int led1=10;
const int led2=11;
const int button=8;
const int analogIN=0;
const int button2=3;
int value=0;
int val;
int analogValue;
int i;
volatile int state=HIGH;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(button,INPUT);
pinMode(button2, INPUT);
attachInterrupt(1,flashing, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(button)==LOW)
{
delay(500);
for(int i=0;i<108;i++)
{
int rate = analogRead(A0);
analogWrite(led1,i);
analogWrite(led2,108-i);
delay(50);
}
}
else
analogWrite (led1,analogIN);
analogWrite (led2,analogIN);
int val = analogRead(A0);
int y = map(val,0,1023, 0,255);
analogWrite (led1,y);
analogWrite(led2,255-y);
delay(20);
Serial.print("button 2 is = ");
Serial.println(button2);
delay(50);
}
void flashing()
{
if(digitalRead(button==HIGH))
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
}
댓글 1
조회수 3,398master님의 댓글
master 작성일
void flashing(){
static char c=0;
c^=1;
if(c)digitalWrite(led1,1);
else digitalWrite(led1,0);
}