Ввод информации с клавиатуры в ардуино
#include <hidboot.h> #include <usbhub.h> // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include <spi4teensy3.h> #include <SPI.h> #endif class KbdRptParser : public KeyboardReportParser { protected: void OnKeyDown (uint8_t mod, uint8_t key); }; void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) { Serial.write(key); } USB Usb; //USBHub Hub(&Usb); HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb); uint32_t next_time; KbdRptParser Prs; void setup() { Serial.begin( 115200 ); #if !defined(__MIPSEL__) while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection #endif if (Usb.Init() == -1) { while(1) { Serial.write(200); //Выводим в порт код 200, если не удалось инициализировать шилд delay(500); } } delay( 200 ); next_time = millis() + 5000; HidKeyboard.SetReportParser(0, &Prs); } void loop() { Usb.Task(); }
Категория: Исходный код