HowTo-Color (8) / Hacking Electronics / Simon Monk / 236-3 / Chapter 6
CHAPTER 6: Hacking Arduino
147
button while in a word processor. So, in terms of security, it is about as secure as writing your password on a sticky note and attaching it to your computer monitor! The sketch is very simple. The first step is to define a variable to contain your password. You will need to change this to your password. We then define the pin to use for the switch. // password // Arduino Leonardo Only char* password = "mysecretpassword"; const int buttonPin = 2;
The Leonardo has access to special keyboard and mouse features not available to other types of Arduino. So, in the “setup” function, the Keyboard feature is started with the line “Keyboard.begin()”. void setup() { pinMode(buttonPin, INPUT_PULLUP); Keyboard.begin(); }
In the main loop, the button is checked with a digital read. If the button is pressed, then the Leonardo uses “Keyboard.print” to send the password. It then waits two seconds to prevent the password being sent multiple times. void loop() { if (! digitalRead(buttonPin)) { Keyboard.print(password); delay(2000); } }
Summary This chapter should have got you started using the Arduino and given you some food for thought for clever hacks using it. It has, however, only scratched the surface of what is possible with this versatile board.
06-ch06.indd 147
1/2/13 11:56 AM