Grading Hot Key Box
From Matt Bilsky
Contents
Overview
For the class I TA, I need to enter the students grade into the CourseSite online each week. The grades are either 100, 95, 85, 75, or 0. My usual approach was to copy 95 to the clip board since that is the most common grade and simply paste it with CTRL-V to save typing. While this worked, if a student got any other grade I would have to look up from the sheet with their work on it and manually type in the grade. A lot of work, right?
I had been reading about the keyboard emulation support on the new Arduino Leonardo boards and was curious how simple it is to implement. This seemed like a perfect opportunity to give it a try.
Finished Product
This is the final product I cooked up:
Each button simply types in the number
Demonstration Video
Here's a quick video of it working:
Internals
Hardware
As mentioned earlier, I used an Arduino Leonardo as the micro controller. While this is certainly overkill, it made the project really really easy.
A simple project box and 5 push button switches from Amazon were used as the inputs.
Each switch has one contact wired to +5 Volts and the other wired both to a digital pin on the Arduino and a 10K Ohm pull-down resistor.
Code
The code is based on the Arduino Keyboard Message Tutorial and very little modification was necessary to make the whole project work. I have included it below:
const int buttonPin1 = 2; // input pin for pushbutton1 int previousbuttonState1 = HIGH; // for checking the state of a pushButton const int buttonPin2 = 3; // input pin for pushbutton int previousbuttonState2 = HIGH; // for checking the state of a pushButton const int buttonPin3 = 4; // input pin for pushbutton int previousbuttonState3 = HIGH; // for checking the state of a pushButton const int buttonPin4 = 5; // input pin for pushbutton int previousbuttonState4 = HIGH; // for checking the state of a pushButton const int buttonPin5 = 6; // input pin for pushbutton int previousbuttonState5 = HIGH; // for checking the state of a pushButton void setup() { // make the pushButton pin an input: pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); // initialize control over the keyboard: Keyboard.begin(); } void loop() { //button 1 // read the pushbutton: int buttonState1 = digitalRead(buttonPin1); // if the button state has changed, if ((buttonState1 != previousbuttonState1) // and it's currently pressed: && (buttonState1 == HIGH)) { // increment the button counter Keyboard.print("100"); } // save the current button state for comparison next time: previousbuttonState1 = buttonState1; // button2 // read the pushbutton: int buttonState2 = digitalRead(buttonPin2); // if the button state has changed, if ((buttonState2 != previousbuttonState2) // and it's currently pressed: && (buttonState2 == HIGH)) { // increment the button counter Keyboard.print("95"); } // save the current button state for comparison next time: previousbuttonState2 = buttonState2; //button 3 // read the pushbutton: int buttonState3 = digitalRead(buttonPin3); // if the button state has changed, if ((buttonState3 != previousbuttonState3) // and it's currently pressed: && (buttonState3 == HIGH)) { // increment the button counter Keyboard.print("85"); } // save the current button state for comparison next time: previousbuttonState3 = buttonState3; //button 4 // read the pushbutton: int buttonState4 = digitalRead(buttonPin4); // if the button state has changed, if ((buttonState4 != previousbuttonState4) // and it's currently pressed: && (buttonState4 == HIGH)) { // increment the button counter Keyboard.print("75"); } // save the current button state for comparison next time: previousbuttonState4 = buttonState4; //button 5 // read the pushbutton: int buttonState5 = digitalRead(buttonPin5); // if the button state has changed, if ((buttonState5 != previousbuttonState5) // and it's currently pressed: && (buttonState5 == HIGH)) { // increment the button counter Keyboard.print("0"); } // save the current button state for comparison next time: previousbuttonState5 = buttonState5; delay(100); }
Wrap-Up
The project took about 1.5 hours and works great! It's a great project if one is interested in getting started with the Arduino Leonardo and also make a cool computer accessory. In the future I would like to possible make it wireless with bluetooth and a battery pack.