Hardware Reference
In-Depth Information
There are no external components for this project, with the exception of a
USB keyboard, and a cable to convert the micro-USB port to a USB port. The
other USB port will be connected to a computer to see the serial output. Serial
communications will be at 9,600 baud.
Source Code
Time to write the sketch, as shown in Listing 20-1.
Listing 20-1: Sketch (fi lename: Chapter20.ino )
1 #include <KeyboardController.h>
2
3 // Key pressed
4 int curkeycode = 0;
5
6 // Initialize USB Controller
7 USBHost usb;
8
9 // Attach keyboard controller to USB
10 KeyboardController keyboard(usb);
11
12 void setup()
13 {
14 Serial.begin(9600);
15 Serial.println("Program started");
16 delay(200);
17 }
18
19 void loop()
20 {
21 keyloop();
22 }
23
24 // This function intercepts key press
25 void keyPressed()
26 {
27 curkeycode = keyboard.getKey();
28 }
29
30 // Sort the final sentence
31 void sortSentence(String sentence)
32 {
33 // Sentence logic goes here
34 Serial.println(sentence);
35 }
36
37 void keyloop()
38 {
 
Search WWH ::




Custom Search