IT/아두이노

[아두이노] 키보드 라이브러리 사용하기

크몽 '경매하는 개발자' 님의 경매/부동산/IT/사업 채널 2022. 1. 8. 01:54
반응형

본인이 가지고 있는 아두이노 우노 기판을 이용하여 키보드 라이브러리를 사용하고자 하니, "Using legacy HID Core (non pluggable)"이라는 에러가 났다.

반응형

 

 

https://www.arduino.cc/reference/en/language/functions/usb/keyboard/

 

Keyboard - Arduino Reference

Description The keyboard functions enable 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port. Note: Not every possible ASCII character, particularly the non-printing ones, can be sent with the

www.arduino.cc

사이트에서 키보드 라이브러리에 관한 글을 읽어보니, 특정 기판에서만 사용이 가능하다는 것을 알았다.

32u4나 SAMD 마이크로 기반의 보드만 가능하다.

The keyboard functions enable 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port.

 

Leonardo, Esplora, Zero, Due and MKR Family 만 가능하다고 하니 레오나르도 아두이노 기판을 샀다. (6500원)

반응형

 

 


회로는 +는 5V, -는 GND, OUTPUT은 아날로그 A0에 꽂고 30초동안 아무 소리도 들리지 않으면 F2키를 누르는 회로를 구성하였다. (42데시벨을 넘기면 n = 0으로 회귀됨)

반응형

 

#include <Keyboard.h>

#define VK_F2             0x71

int SoundSensor = A0;     // 사운드 센서 설정
int n=0;

void setup() {               
    Serial.begin(9600); // 시리얼모니터 사용
    pinMode(SoundSensor,INPUT);
}

void loop() {     
   int level = analogRead(SoundSensor);

   if(level > 43){
         Serial.print(level);
         Serial.println(" dB");
         n = 0;
   }
   else{
    delay(1000);
    n++;
    Serial.println(n);
   }
   
  if (n > 60) {
      Keyboard.write(KEY_F2);
      n = 0;
        }
}
반응형