Update pro_micro.ino

This commit is contained in:
2020-02-01 17:17:35 +00:00
parent 282a12bcce
commit c824a4bb91
+24 -16
View File
@@ -25,28 +25,36 @@ Auch hilfreich:
*/
int RXLED = 17; // The RX LED has a defined Arduino pin
// The TX LED was not so lucky, we'll need to use pre-defined
// macros (TXLED1, TXLED0) to control that.
// (We could use the same macros for the RX LED too -- RXLED1,
// and RXLED0.)
#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
// TX LED is set as an output behind the scenes
pinMode(buttonPin, INPUT_PULLUP);
digitalWrite(buttonPin, HIGH);
Serial.begin(9600); //This pipes to the serial monitor
Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
Keyboard.begin();
}
void loop() {
Serial.println("Hello world"); // Print "Hello World" to the Serial Monitor
Serial1.println("Hello!"); // Print "Hello!" over hardware UART
buttonState = digitalRead(buttonPin);
if ((buttonState != prevButtonState) && (buttonState == HIGH)) {
Serial.println("Now pressing button");
digitalWrite(RXLED, LOW); // set the LED on
TXLED0; //TX LED is not tied to a normally controlled pin
delay(3000); // wait for a second
digitalWrite(RXLED, HIGH); // set the LED off
TXLED1;
delay(3000); // wait for a second
// Here starts the output action
//Keyboard.press(KEY_LEFT_GUI); // Command key in Mac, use KEY_LEFT_CTRL for Pc
Keyboard.press('v');
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;
}