1 minute read
Summary
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.
148 Hacking Electronics
For more information on programming the Arduino, you may wish to look at some of the author’s other books on this topic. Programming Arduino: Getting Started with Sketches assumes no prior programming experience and will show you how to program the Arduino from first principals. 30 Arduino Projects for the Evil Genius is a project-based book that explains both the hardware and programming side of Arduino, and is illustrated with example projects, nearly all of which are built on breadboard.
The official Arduino web site, www.arduino.cc, has a wealth of information on using the Arduino, as well as the official documentation for the Arduino commands and libraries.