Creative Code

EX03_binary_led_interrupt -(2) (2,3번핀이 아닌 다른핀에 버튼을 연결할때) 본문

Arduino(C,C++)

EX03_binary_led_interrupt -(2) (2,3번핀이 아닌 다른핀에 버튼을 연결할때)

빛하루 2023. 8. 11. 12:30
#include "PinChangeInterrupt.h"
const int led[6] = {8,9,10,11,12,13};
const int SW_0 = 4;
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);
  }
  attachPCINT(digitalPinToPCINT(SW_0),SW0_Pressed,RISING); // 2,3번핀이 아닌 다른 핀에 버튼을 연결할 때는 attachPCINT를 쓴다, 헤더파일 다운로드 후 포함필수
}

void loop() {
  // put your main code here, to run repeatedly:

}