Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* @file CustomKeypad.pde
- || @version 1.0
- || @author Alexander Brevig
- || @contact alexanderbrevig@gmail.com
- ||
- || @description
- || | Demonstrates changing the keypad size and key values.
- || #
- */
- #include <Keypad.h>
- JoyState_t joySt;
- const byte ROWS = 4; //four rows
- const byte COLS = 6; //four columns
- //define the cymbols on the buttons of the keypads
- uint32_t values[] = {
- 0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000 };
- char hexaKeys[ROWS][COLS] = {
- {1,2,3,4,5,6},
- {7,8,9,10,11,12},
- {13,14,15,16,17,18},
- {19,20,21,22,23,24}};
- byte rowPins[ROWS] = {
- 8, 5, 3, 4}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {
- 6, 7, 13, 11,10,9}; //connect to the column pinouts of the keypad
- //initialize an instance of class NewKeypad
- Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup(){
- //Serial.begin(9600);
- joySt.xAxis = 0;
- joySt.yAxis = 0;
- joySt.zAxis = 0;
- joySt.xRotAxis = 0;
- joySt.yRotAxis = 0;
- joySt.zRotAxis = 0;
- joySt.throttle = 0;
- joySt.rudder = 0;
- joySt.hatSw1 = 0;
- joySt.hatSw2 = 0;
- joySt.buttons = 0;
- }
- void loop(){
- joySt.xAxis = analogRead(A0)/4;
- joySt.yAxis = analogRead(A1)/4;
- joySt.zAxis = analogRead(A2)/4;
- joySt.xRotAxis = analogRead(A3)/4;
- joySt.yRotAxis = analogRead(A4)/4;
- char customKey = customKeypad.getKey();
- joySt.buttons = 0;
- if (customKey){
- joySt.buttons = values[customKey-1];
- //Serial.println(joySt.buttons,BIN);
- //Serial.println(joySt.buttons,HEX);
- //joySt.buttons = 0x100;
- }
- Joystick.setState(&joySt);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement