Files
microcontroller/pro_micro/pro_micro.ino
T
2020-06-13 20:35:39 +02:00

62 lines
2.4 KiB
Arduino
Executable File

/* Pro Micro Test Code
Code von https://codebender.cc/sketch:77845#Pro%20Micro%20Blink.ino (Blinken) und https://www.instructables.com/id/Arduino-Programmable-Button-Panel-As-Keyboard/ (Button)
Zuerst musste unter Ubuntu der Modem Manager entfernt werden mit, s. https://community.arduboy.com/t/resolved-issues-uploading-with-ubuntu-18-10-and-arduino-1-8-9/7447/4
sudo systemctl disable ModemManager.service
In den Preferences die zusätzliche Quell-URL eintragen, s. https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/all#installing-mac--linux
https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json
Danach über den Board Manager die Sparkfun AVR installieren und als Board "Sparkfun Pro Micro" und Provil 5V 16MHz auswählen.
Upload über den neuen seriellen Port /dev/ACM3
Troubleshooting, wenn bricked:
- ModemManager abschalten
sudo systemctl disable ModemManager.service
- Pro Micro mit USB-Port verbinden
- 2x schnell hintereinander RST mit GND verbinden, danach 8s Zeit für den Upload https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/troubleshooting-and-faq#ts-revive
- Upload mit
sudo ./arduino --upload /root/Arduino/pro_micro/pro_micro.ino --port /dev/ttypACM3
Auch hilfreich:
ls /dev/input/by-id/
ls /dev/ttyA*
lsusb
screen /dev/ttyACM0 9600 # Serial Monitor im Terminal
*/
#include "Keyboard.h"
const int RXLED = 17; // The RX LED has a defined Arduino pin
const int buttonPin = 2;
int buttonState = 0;
int prevButtonState = HIGH;
void setup() {
Serial.println("Hello Keyboard World");
pinMode(RXLED, OUTPUT); // Set RX LED as an output
pinMode(buttonPin, INPUT_PULLUP);
digitalWrite(buttonPin, HIGH);
Serial.begin(9600); //This pipes to the serial monitor
Keyboard.begin();
}
void loop() {
buttonState = digitalRead(buttonPin);
if ((buttonState != prevButtonState) && (buttonState == HIGH)) {
Serial.println("Now pressing button");
// Here starts the output action
//Keyboard.press(KEY_LEFT_GUI); // Command key in Mac, use KEY_LEFT_CTRL for Pc
Keyboard.press('v');
//Keyboard.press(KEY_LEFT_SHIFT);
delay(100);
Keyboard.releaseAll(); // This is important after every Keyboard.press it will continue to be pressed
//digitalWrite(RXLED, LOW); // set the LED on
//delay(300);
//digitalWrite(RXLED, HIGH); // set the LED off
}
prevButtonState = buttonState;
}