Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
/* keyPadHiduino Example Code
by: Jim Lindblom
date: January 5, 2012
license: MIT license. If you find this code useful, please
feel free to use this code however you'd like, commercially
or otherwise. Just keep this license on there whatever you do.
This code implements a 12-key USB keypad. You can type 0-9,
* is the + sign and the # key is enter. I'm using SparkFun's
12-button keypad, your pinouts may vary. Multi-touch is
not supported.
SparkFun Keypad Pinout:
Rows and columns are connected as such:
-------------
| 1 | 2 | 3 | - 3
| 4 | 5 | 6 | - 7
| 7 | 8 | 9 | - 6
| * | 0 | # | - 1
-------------
| | |
2 4 5
*/
// Pins 1-7 of the keypad connected to the Arduino respectively:
void setup()
{
}
void loop()
{
delayMicroseconds(1);
{
sendKeyPress(keypadStatus); // continue to send the button over USB
}
}
/* sendKeyPress(int key): This function sends a single key over USB
It requires an int, of which the 12 LSbs are used. Each bit in
key represents a single button on the keypad.
This function will only send a key press if a single button
is being pressed */
switch(key)
{
case 1: // 0x001
break;
case 2: // 0x002
Keyboard.write('2');
break;
case 4: // 0x004
Keyboard.write('3');
break;
case 8: // 0x008
Keyboard.write('4');
break;
Keyboard.write('5');
break;
break;
Keyboard.write('7');
break;
Keyboard.write('8');
break;
Keyboard.write('9');
break;
Keyboard.write('+');
break;
break;
break;
}
/* getKeypadStatus(): This function returns an int that represents
the status of the 12-button keypad. Only the 12 LSb's of the return
value hold any significange. Each bit represents the status of a single
key on the button pad. '1' is bit 0, '2' is bit 1, '3' is bit 2, ...,
'#' is bit 11.
This function doesn't work for multitouch.
*/
int getKeypadStatus()
{
pinMode(keypadPins[i], INPUT);
digitalWrite(keypadPins[i], HIGH);
}
if (!digitalRead(columnPins[col]))
{
}
}
}
return keypadStatus;
}
/* HID Joystick Mouse Example
by: Jim Lindblom
date: 1/12/2012
license: MIT License - Feel free to use this code for any purpose.
No restrictions. Just keep this license if you go on to use this
code in your future endeavors! Reuse and share.
This is very simplistic code that allows you to turn the
SparkFun Thumb Joystick (http://www.sparkfun.com/products/9032)
into an HID Mouse. The select button on the joystick is set up
as the mouse left click.
*/
int vertZero, horzZero; // Stores the initial value of each axis, usually around
512
const int sensitivity = 200; // Higher sensitivity value = slower mouse, should
be <= about 500
int mouseClickFlag = 0;
void setup()
pinMode(vertPin, INPUT);
void loop()
if (vertValue != 0)
Mouse.move(0, vertValue/sensitivity, 0); // move mouse on y axis
if (horzValue != 0)
{
mouseClickFlag = 1;
}
{
mouseClickFlag = 0;
}