May 15, 2021 Arduino
This example listens for a byte from the serial port. /b10> When received, the board sends a keystroke back to the computer. /b11> The keystrokes you send are one higher than the keystrokes you receive, so if you send an "a" from a serial monitor, you receive a "b" from the board connected to your computer. /b12> "1" returns "2" and so on.
Warning - When you use the Keyboard.print() command, the Leonardo, Micro, or Due board takes over the keyboard of your computer. /b10> To ensure that you do not lose control of your computer when you run sketches with this feature, set up a reliable control system before calling Keyboard.print(). T his sketch is designed to send a keyboard command only after the board receives a byte through a serial port.
You will need the following components:
Simply connect the board to your computer using a USB cable.
Turn on the Arduino IDE software on your computer. U se arduino to encode and control your circuitry. /b11> Open a new sketch file by clicking New.
Note - You must include the keyboard library in the Arduino library file. /b10> Copy and paste the keyboard library file into the following yellow file called "libraries".
/* Keyboard test For the Arduino Leonardo, Micro or Due Reads a byte from the serial port, sends a keystroke back. The sent keystroke is one higher than what's received, e.g. if you send a, you get b, send A you get B, and so forth. The circuit: * none */ #include "Keyboard.h" void setup() { // open the serial port: Serial.begin(9600); // initialize control over the keyboard: Keyboard.begin(); } void loop() { // check for incoming serial data: if (Serial.available() > 0) { // read incoming serial data: char inChar = Serial.read(); // Type the next ASCII value from what you received: Keyboard.write(inChar + 1); } }
Once you start programming, open your serial monitor and send a byte. T he board will reply with a keystroke, which is a higher number.
When you send a byte, the board will reply to a higher number of keystrokes on the Arduino IDE serial monitor.