Notice
Recent Posts
Recent Comments
Creative Code
EX03_binary_led_interrupt -(1) (버튼누를 때마다 다음 이진수 led출력) 본문
const int led[6] = {8,9,10,11,12,13};
const int SW_0 = 2;
const int SW_1 = 3;
int cnt =0;
void SW0_Pressed(void) {
for (int i = 0; i<6; i++) {
digitalWrite(led[i],cnt&(0x01 << i) ? HIGH : LOW);
}
cnt++;
}
void setup() {
// put your setup code here, to run once:
for (int i = 0; i<6; i++) {
pinMode(led[i],OUTPUT);
}
attachInterrupt(digitalPinToInterrupt(SW_0),SW0_Pressed,RISING); //0에서 1로 바뀔때 SW0_Pressed 함수를 수행
//attachInterrupt 를 사용하면 loop문을 안돌아도 내부 칩에서 자체적으로 명령을 수행한다.
}
void loop() {
// put your main code here, to run repeatedly:
}
'Arduino(C,C++)' 카테고리의 다른 글
EX03_binary_led_interrupt -(2) (2,3번핀이 아닌 다른핀에 버튼을 연결할때) (0) | 2023.08.11 |
---|---|
06_SW_INPUT_interrupt(스위치누를때마다 led on/off) (0) | 2023.08.11 |
05_SW_INPUT (0) | 2023.08.10 |
04_Serial_Read (0) | 2023.08.10 |
EX02_DC_MOTOR (1) | 2023.08.10 |