Page 75 - 최강 아두이노 퍼스트 참고서
P. 75
int pin = 13; volatile int
state = LOW; int
old_state=state; int
count_change=0;
void setup()
{
Serial.begin(9600); pinMode(pin,
OUTPUT);
attachInterrupt(0, blink, CHANGE);
Serial.println("setup end");
}
void loop()
{
digitalWrite(pin, state);
if( state !=old_state )
{
Serial.print("changeed "); old_state=state;
count_change+=1; // count_change = count_change + 1;
Serial.print("state counting");
Serial.print("count_change -->");
Serial.println(count_change);
}
}
void blink()
{
state = !state; }
75