Created
May 19, 2015 14:57
-
-
Save mikewallace1979/996446766f6b1f2da45c to your computer and use it in GitHub Desktop.
s49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Keypad.h> | |
const byte rows = 7; | |
const byte cols = 14; | |
char keys[rows][cols] = { | |
{'a', 'b', 'c', 'd', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'}, | |
{'e', 'f', 'g', 'h', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28'}, | |
{'i', 'j', 'k', 'l', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42'}, | |
{'m', 'n', 'o', 'p', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56'}, | |
{'q', 'r', 's', 't', 'u', '62', '63', '64', '65', '66', '67', '68', '69', '70'}, | |
{'v', 'w', 'x', 'y', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84'}, | |
{'z', 'A', 'B', 'C', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98'} | |
}; | |
int notes[98] = { | |
84, | |
80, | |
83, | |
79, | |
82, | |
78, | |
81, | |
77, | |
80, | |
76, | |
79, | |
75, | |
78, | |
74, | |
77, | |
73, | |
76, | |
72, | |
75, | |
71, | |
74, | |
70, | |
73, | |
69, | |
72, | |
68, | |
71, | |
67, | |
70, | |
66, | |
69, | |
65, | |
68, | |
64, | |
67, | |
63, | |
66, | |
62, | |
65, | |
61, | |
64, | |
60, | |
63, | |
59, | |
62, | |
58, | |
61, | |
57, | |
60, | |
56, | |
59, | |
55, | |
58, | |
54, | |
57, | |
53, | |
56, | |
52, | |
55, | |
51, | |
54, | |
50, | |
53, | |
49, | |
52, | |
48, | |
51, | |
47, | |
50, | |
46, | |
49, | |
45, | |
48, | |
44, | |
47, | |
43, | |
46, | |
42, | |
45, | |
41, | |
44, | |
40, | |
43, | |
39, | |
42, | |
38, | |
41, | |
37, | |
40, | |
36, | |
39, | |
35, | |
38, | |
34, | |
37, | |
33, | |
36, | |
32 | |
}; | |
byte rowPins[rows] = {32, 33, 34, 35, 36, 37, 38}; | |
byte colPins[cols] = {39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52}; | |
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols); | |
String msg; | |
void setup() { | |
Serial.begin(31250); | |
msg = ""; | |
keypad.setHoldTime(-1); | |
keypad.addEventListener(keypadEvent); //add an event listener | |
keypad.setDebounceTime(5); | |
} | |
void loop() { | |
//char key = keypad.getKey(); | |
//if (key != NO_KEY) {// && key != '2') { | |
// Serial.println(key); | |
//} | |
keypad.getKeys(); | |
} | |
// plays a MIDI note. Doesn't check to see that | |
// cmd is greater than 127, or that data values are less than 127: | |
void noteOn(int cmd, int pitch, int velocity) { | |
Serial.write(cmd); | |
Serial.write(pitch); | |
Serial.write(velocity); | |
} | |
//take care of some special events | |
void keypadEvent(KeypadEvent eKey) { | |
int cmd; | |
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list. | |
{ | |
if ( keypad.key[i].stateChanged ) // Only find keys that have changed state. | |
{ | |
switch (keypad.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED | |
case PRESSED: | |
cmd = 144; | |
break; | |
case HOLD: | |
msg = " HOLD."; | |
break; | |
case RELEASED: | |
cmd = 128; | |
break; | |
case IDLE: | |
cmd = 128; | |
} | |
//Serial.print("Key "); | |
//Serial.print(keypad.key[i].kcode); | |
//Serial.println(msg); | |
noteOn(cmd, notes[keypad.key[i].kcode], 127); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment