1 minute read

How to Type Passwords Automatically

Next Article
Index

Index

CHAPTER 6: Hacking Arduino 145

The function “setPins” does not do much except conveniently put the commands to set the state for each control pin into a single convenient line. Most of the logic lives in the “setPin” function that it calls.

void setPins(int p1, int p2, int p3) { setPin(pin1, p1); setPin(pin2, p2); setPin(pin3, p3); }

The “setPin” function sets the state of the pin supplied as its first argument. If the value of the state is –1, then the pin mode for the pin is set to INPUT. Otherwise, it is assumed to be a 1 or a 0 and the pin is set to be an OUTPUT and set to the value supplied with a call to “digitalWrite”.

void setPin(int pin, int value) { if (value == -1) { pinMode(pin, INPUT); } else { pinMode(pin, OUTPUT); digitalWrite(pin, value); } }

How to Type Passwords Automatically

The Arduino Leonardo can be used to impersonate a USB keyboard. Unfortunately, this is not true of the Arduino Uno, so in this section you will need an Arduino Leonardo.

Figure 6-35 shows the device we are going to construct.

All that happens when you press the button is that the Arduino Leonardo pretends to be a keyboard and types the password set in the sketch, wherever the cursor happens to be.

This article is from: