ChordJoy is a keyboard application that accepts chordal input from a set of digital ports, outputting letters and the chords that correspond to the piano keyboard keys the user has pressed.

Dependencies:   PinDetect_KL25Z mbed-rtos mbed

Fork of ChordJoy by Interactive Device Design

Files at this revision

API Documentation at this revision

Comitter:
andrewhead
Date:
Mon Sep 22 06:14:29 2014 +0000
Parent:
4:400a042e762a
Commit message:
Ready to publish.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 400a042e762a -r 1186eb1f3c2b main.cpp
--- a/main.cpp	Mon Sep 22 02:15:15 2014 +0000
+++ b/main.cpp	Mon Sep 22 06:14:29 2014 +0000
@@ -8,7 +8,7 @@
 
 // Collection is the time that it takes after pressing one key and then reading
 // all the keys to determine what the chord is.
-const int COLLECTION_MS = 500;
+const int COLLECTION_MS = 200;
 Timer collectionTimer;
 
 InterruptIn buttons [BUTTONS] = {
@@ -44,35 +44,37 @@
     10000000 // inaudible pitch
 };
 // Possible chords that can be played.
+// Chords consist of 3 notes, and an integer for the ASCII character
+//  that it will output via serial.
 // Note that 7 is no button pressed, or a 'silent' pitch.
-int chords [LETTERS][BUZZERS] = {
-    {0, 7, 7}, // single notes
-    {1, 7, 7},
-    {2, 7, 7},
-    {3, 7, 7},
-    {4, 7, 7},
-    {5, 7, 7},
-    {6, 7, 7},
-    {0, 2, 7}, // diads
-    {0, 3, 7},
-    {0, 4, 7},
-    {0, 5, 7},
-    {1, 3, 7},
-    {1, 4, 7},
-    {1, 5, 7},
-    {1, 6, 7},
-    {2, 4, 7},
-    {2, 5, 7},
-    {2, 6, 7},
-    {3, 4, 7},
-    {3, 5, 7},
-    {4, 6, 7},
-    {0, 2, 4}, // triads
-    {0, 2, 5},
-    {0, 3, 5},
-    {1, 4, 6},
-    {1, 3, 4},
-    {1, 3, 6}
+int chords [LETTERS][BUZZERS + 1] = {
+    {0, 7, 7, 114}, // single notes
+    {1, 7, 7, 32},
+    {2, 7, 7, 106},
+    {3, 7, 7, 107},
+    {4, 7, 7, 109},
+    {5, 7, 7, 113},
+    {6, 7, 7, 122},
+    {0, 2, 7, 115}, // diads
+    {0, 3, 7, 112},
+    {0, 4, 7, 110},
+    {0, 5, 7, 102},
+    {1, 3, 7, 105},
+    {1, 4, 7, 98},
+    {1, 5, 7, 103},
+    {1, 6, 7, 104},
+    {2, 4, 7, 100},
+    {2, 5, 7, 121},
+    {2, 6, 7, 120},
+    {3, 4, 7, 99},
+    {3, 5, 7, 117},
+    {4, 6, 7, 119},
+    {0, 2, 4, 101}, // triads
+    {0, 2, 5, 118},
+    {0, 3, 5, 108},
+    {1, 3, 6, 97},
+    {1, 4, 6, 116},
+    {1, 3, 4, 111}
 };
 
 void playChord(int chordIndex) {
@@ -103,7 +105,7 @@
 
 void registerButtonInterrupts(void) {
     for (int i =  0; i < BUTTONS; i++) {
-        buttons[i].rise(&setFlag);
+        buttons[i].fall(&setFlag);
     }   
 }
 
@@ -115,7 +117,7 @@
     int firstThreeButtons[BUZZERS] = {7, 7, 7};
     int pressedCount = 0;
     for (int i = 0; i < BUTTONS; i++) {
-        if (buttons[i].read() == 1) {
+        if (buttons[i].read() == 0) {
             firstThreeButtons[pressedCount] = i;
             pressedCount++;   
         }
@@ -137,7 +139,7 @@
             break;
         }
     }
-    pc.printf("Matched chord %d\n", matchIndex);
+    // pc.printf("Matched chord %d\n", matchIndex);
     return matchIndex;
 }
 
@@ -149,7 +151,9 @@
             collectionTimer.reset();
             int chordIndex = readChord();
             if (chordIndex != -1) {
-                playChord(chordIndex);   
+                playChord(chordIndex);
+                int charAscii = chords[chordIndex][BUZZERS];
+                pc.printf("%c", charAscii);
             }
         }
         wait_ms(10);