CHAPTER20

USBHost

This chapter discusses the following functions:

  • keyPressed()
  • keyReleased()
  • getModifiers()
  • getKey()
  • getOemKey()
  • mouseMoved()
  • mouseDragged()
  • mousePressed()
  • mouseReleased()
  • getXChange()
  • getYChange()
  • getButton()

The hardware needed to use these functions includes:

  • Arduino Due
  • USB keyboard
  • USB OTG micro adapter

You can find the code download for this chapter at http://www.wiley.com/go/arduinosketches on the Download Code tab. The code is in the Chapter 20 folder and the filename is Chapter 20.ino.

Introducing USBHost

Most people do not understand the nightmares that some computer users previously had when adding peripherals. When the PC originally shipped, it did not have a mouse as standard; you needed to buy that separately. It came with a keyboard, but that is about it. The keyboard was a standard element to computers, and it still is. Since there is no need to have two keyboards connected to a computer, each PC came with a single keyboard connector, the DIN keyboard connector. It was large and bulky, and kept the connector firmly in place. Then manufacturers decided to add a mouse. Mice were normally sold with a serial connector, the highly reliable RS-232 connector. Because most computers were sold with two serial ports and one parallel port, that was easy. It left ports free.

Suppose the user wanted to add a printer. Printers were almost always connected to parallel ports, but the computer had only one. Then a 56-k modem connected to the remaining serial ...

Get Arduino Sketches: Tools and Techniques for Programming Wizardry now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.