Min menu

Pages

Project 32 :Keyboard Serial

 Console Serial 


This model tunes in for a byte coming from the sequential port. At the point when gotten, the board sends a keystroke back to the PC. The sent keystroke is one higher than what is gotten, so on the off chance that you send "a" from the chronic screen, you'll get a "b" from the board associated with the PC. A "1" will restore a "2, etc. 


NB: When you utilize the Keyboard.print() order, the Leonardo, Micro or Due board assumes control over your PC's console! To protect you don't lose control of your PC while running a sketch with this capacity, make a point to set up a solid control framework before you call Keyboard.print(). This sketch is intended to just send a Keyboard order after the board has gotten a byte over the sequential port. 


Equipment Required 


Arduino Leonardo, Micro, or Due board 


Circuit 



Associate your board to your PC with a miniature USB link. 


When customized, open your chronic screen and send a byte. The board will answer with a keystroke that is one number higher.





Code

/* 
 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 

 created 21 Oct 2011 
 modified 27 Mar 2012 
 by Tom Igoe 

 This example code is in the public domain. 

 http://www.arduino.cc/en/Tutorial/KeyboardSerial
 */ 


#include "Keyboard.h" 
#include "HID.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 
    // read incoming serial data: 
    char inChar Serial read 
    // Type the next ASCII value from what you received: 
    Keyboard. write inChar 
  
}
reaction: