PDA

View Full Version : 6x8 keypad on Teensy 2.0



sardauker
12-05-2012, 04:13 PM
(I googled and searched here and tryied every debug and/or combo that I was aware of. If I've missed something, please forgive me)

I am trying to realize a 6x8 keypad with keypad library (http://www.pjrc.com/teensy/td_libs_Keypad.html), changing the code in this way:


#include <Keypad.h>


int led = 11;
const byte ROWS = 8;
const byte COLS = 6;

byte rowPins[ROWS] = {20, 19, 10, 9, 8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {17, 12, 13, 14, 15, 16}; //connect to the column pinouts of the keypad - avoided 11


char keys[ROWS][COLS] = {
{'11', '12', '13', '14', '15', '16'},
{'21', '22', '23', '24', '25', '26'},
{'31', '32', '33', '34', '35', '36'},
{'41', '42', '43', '44', '45', '46'},
{'51', '52', '53', '54', '55', '56'},
{'61', '62', '63', '64', '65', '66'},
{'71', '72', '73', '74', '75', '76'},
{'81', '82', '83', '84', '85', '86'},
};



// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup ()
{
// initialize control over the keyboard:
Keyboard.begin();
pinMode(led, OUTPUT);
} // end of setup

void loop ()
{
//heartbeat
digitalWrite(led, HIGH); // turn the LED on
delay(200); // lascia acceso
digitalWrite(led, LOW); // spegne
delay(200); // pausa
digitalWrite(led, HIGH); // turn the LED on
delay(200); //lascia acceso
digitalWrite(led, LOW); // fine hearthbeat
delay(1000); // wait for a second




byte key = kpd.getKey();
if (!key)
return;

switch (key)
{
case '11': Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT | MODIFIERKEY_SHIFT ); Keyboard.println (F("11")); Keyboard.set_modifier(0); break;
case '12': Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT | MODIFIERKEY_SHIFT ); Keyboard.set_key1(KEY_DELETE); Keyboard.send_now(); Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now() ; break;
case '13': Keyboard.println (" 31"); break;
case '14': Keyboard.println (F(" 41")); break;
case '15': Keyboard.println (F(" 51")); break;
case '16': Keyboard.println (F(" 61")); break;
case '21': Keyboard.println (F(" 71")); break;
case '22': Keyboard.println (F(" 81")); break;
case '23': Keyboard.println (F(" 91")); break;
case '24': Keyboard.println (F(" *1")); break;
case '25': Keyboard.println (F(" 01")); break;
case '26': Keyboard.println (F(" #1")); break;
case '31': Keyboard.println (F(" 12")); break;
case '32': Keyboard.println (F(" 22")); break;
case '33': Keyboard.println("Hello World ");
case '34': Keyboard.println (F(" 42")); break;
case '35': Keyboard.println (F(" 52")); break;
case '36': Keyboard.println (F(" 62")); break;
case '41': Keyboard.println (F(" 72")); break;
case '42': Keyboard.println (F(" 82")); break;
case '43': Keyboard.println (F(" 92")); break;
case '44': Keyboard.println (F(" *2")); break;
case '45': Keyboard.println (F(" 02")); break;
case '46': Keyboard.println (F(" #2")); break;
case '51': Keyboard.println (F(" 13")); break;
case '52': Keyboard.println (F(" 23")); break;
case '53': Keyboard.println (F(" 33")); break;
case '54': Keyboard.println (F(" 43")); break;
case '55': Keyboard.println (F(" 53")); break;
case '56': Keyboard.println (F(" 63")); break;
case '61': Keyboard.println (F(" 73")); break;
case '62': Keyboard.println (F(" 83")); break;
case '63': Keyboard.println (F(" 93")); break;
case '64': Keyboard.println (F(" *3")); break;
case '65': Keyboard.println (F(" 03")); break;
case '66': Keyboard.println (F(" #3")); break;
case '71': Keyboard.println (F(" 14")); break;
case '72': Keyboard.println (F(" 24")); break;
case '73': Keyboard.println (F(" 34")); break;
case '74': Keyboard.println (F(" 44")); break;
case '75': Keyboard.println (F(" 54")); break;
case '76': Keyboard.println (F(" 64")); break;
case '81': Keyboard.println (F(" 74")); break;
case '82': Keyboard.println (F(" 84")); break;
case '83': Keyboard.println (F(" 94")); break;
case '84': Keyboard.println (F(" *4")); break;
case '85': Keyboard.println (F(" 04")); break;
case '86': Keyboard.println (F(" #4")); break;




} // end of switch

// go back to main messages






} // end of loop



I have tried swapping rows with colums, using single digit cases, changing the print line to something like


case '1': Keyboard.print("senza ln 11"); Keyboard.println(key); break;

But I had nothing back. It simply does not act as a keyboard, while the heartbeating LED i put as a checkpoint works fine.


Really, I can't see the flaw.


Have I got to declare all the pins as something, somehow? isn't it done in the library?


Thank you in advance.

PaulStoffregen
12-05-2012, 10:42 PM
Don't use quotes around the numbers.

For example, change this:



{'11', '12', '13', '14', '15', '16'},
{'21', '22', '23', '24', '25', '26'},


To this:



{11, 12, 13, 14, 15, 16},
{21, 22, 23, 24, 25, 26},


Don't forget to also change them on the case lines.

sardauker
12-06-2012, 09:32 AM
Thank you, now it works :)

be kind with me, and teach me: is it a general rule -no quotes around switch cases- or if I needed to name a case, don' know, CK or *21, i had to put quotes to discriminate?

Again, thank you very much :)