help with keypad

Status
Not open for further replies.

garyocampo

New member
Hi, i'm currently adapting an 88 key piano I found in the trash to a teensy.
I found the multikey example in the keypad library and thought it would be useful for my purposes.
here is my code:
HTML:
/* @file MultiKey.ino
|| @version 1.0
|| @author Mark Stanley
|| @contact mstanley@technologist.com
||
|| @description
|| | The latest version, 3.0, of the keypad library supports up to 10
|| | active keys all being pressed at the same time. This sketch is an
|| | example of how you can get multiple key presses from a keypad or
|| | keyboard.
|| #
*/

#include <Keypad.h>

const byte ROWS = 8; //four rows
const byte COLS = 11; //three columns
char keys[ROWS][COLS] = {
  {"A0","A1","A2","A3","A4","A5","A6","A7","A8","A9","A10"},
  {"B0","B1","B2","B3","B4","B5","B6","B7","B8","B9","B10"},
  {"C0","C1","C2","C3","C4","C5","C6","C7","C8","C9","C10"},
  {"D0","D1","D2","D3","D4","D5","D6","D7","D8","D9","D10"},
  {"E0","E1","E2","E3","E4","E5","E6","E7","E8","E9","E10"},
  {"F0","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10"},
  {"G0","G1","G2","G3","G4","G5","G6","G7","G8","G9","G10"},
  {"H0","H1","H2","H3","H4","H5","H6","H7","H8","H9","H10"}
};
byte rowPins[ROWS] = {0, 1, 2, 3, 4, 5, 6, 7}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28}; //connect to the column pinouts of the kpd

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

unsigned long loopCount;
unsigned long startTime;
String msg;


void setup() {
    Serial.begin(9600);
    loopCount = 0;
    startTime = millis();
    msg = "";
}


void loop() {
    loopCount++;
    if ( (millis()-startTime)>5000 ) {
        Serial.print("Average loops per second = ");
        Serial.println(loopCount/5);
        startTime = millis();
        loopCount = 0;
    }

    // Fills kpd.key[ ] array with up-to 10 active keys.
    // Returns true if there are ANY active keys.
    if (kpd.getKeys())
    {
        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {
            if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                    case PRESSED:
                    msg = " PRESSED.";
                break;
                    case HOLD:
                    msg = " HOLD.";
                break;
                    case RELEASED:
                    msg = " RELEASED.";
                break;
                    case IDLE:
                    msg = " IDLE.";
                }
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.println(msg);
            }
        }
    }
}  // End loop

and here is my error
HTML:
MultiKey:27: error: too many initializers for 'char [11]'
 };
 ^
MultiKey:27: error: too many initializers for 'char [11]'
MultiKey:27: error: too many initializers for 'char [11]'
MultiKey:27: error: too many initializers for 'char [11]'
MultiKey:27: error: too many initializers for 'char [11]'
MultiKey:27: error: too many initializers for 'char [11]'
MultiKey:27: error: too many initializers for 'char [11]'
MultiKey:27: error: too many initializers for 'char [11]'
too many initializers for 'char [11]'

now I understand that the keys are intended to be in single quotes like so {'a', 'b', 'c'} but since I have 88 keys i thought id use double quotes (the documentation allows it).
I have 11 columns and I initialize 11 pins.
thanks in advance for any help, if i have forgoten something please let me know.
cheers!!!
 
the way you have your array characters set, this would be String rather than char? try setting the array as "String keys[ROWS][COLS] = {" ? just a guess
 
What Morton says.
You can't initialize an array of chars (1 char = 1 byte) with an array of 2-3 chars strings (2-3 bytes each).
 
so, here is the thing. I have a two dimentional array like so:
Code: [Select]

HTML:
{{'1' ,21}, {'2' ,22}, {'3' ,23}, {'4' ,24}, {'5' ,25}, {'6' ,26}, {'7' ,27}, {'8' ,28}, {'9' ,29}, {'0' ,30}, {'a' ,31}, {'b' ,32}, {'c' ,33}, {'d' ,34}, {'e' ,35}, {'f' ,36}, {'g' ,37}, {'h' ,38}, {'i' ,39}, {'j' ,40}, {'k' ,41}, {'l' ,42}, {'m' ,43}, {'n' ,44}, {'o' ,45}, {'p' ,46}, {'q' ,47}, {'r' ,48}, {'s' ,49}, {'t' ,50}, {'u' ,51}, {'v' ,52}, {'w' ,53}, {'x' ,54}, {'y' ,55}, {'z' ,56}, {'A' ,57}, {'B' ,58}, {'C' ,59}, {' ',60}, {'D' ,61}, {'E' ,62}, {'F' ,63}, {'G' ,64}, {'H' ,65}, {'I' ,66}, {'J' ,67}, {'K' ,68}, {'L' ,69}, {'M' ,70}, {'N' ,71}, {'O' ,72}, {'P' ,73}, {'Q' ,74}, {'R' ,75}, {'S' ,76}, {'T' ,77}, {'U' ,78}, {'V' ,79}, {'W' ,80}, {'X' ,81}, {'Y' ,82}, {'Z' ,83}, {'!',84}, {'@',85}, {'#',86}, {'%',87}, {'^',88}, {'&',89}, {'*',90}, {'?',91}, {')',92}, {'-',93}, {'_',94}, {'=',95}, {'+',96}, {'{',97}, {'}',98}, {'[',99}, {']',100}, {':',101}, {';',102}, {'<',103}, {'>',104}, {'.',105}, {',',106}, {'/',107}, {'(',108} };

in my code when i press a button I get a value corresponding to the first element of every array ('<', '3', '{')
what i want is to access the second value of the corresponding array('<' == 103, '3' == 23,'{' == 97).
but i don't want the computational complexity to be O(n^2). I want it to be as fast as possible.
I've been looking and found the STL libraries for arduino but can't get them to work, Does anyone have any ideas?
 
Status
Not open for further replies.
Back
Top