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

Files at this revision

API Documentation at this revision

Comitter:
andrewhead
Date:
Thu Sep 18 05:48:12 2014 +0000
Child:
1:b6b866a58a87
Commit message:
Play all chords on 3 buzzers.

Changed in this revision

PinDetect_KL25Z.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
pwmout.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect_KL25Z.lib	Thu Sep 18 05:48:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/bjo3rn/code/PinDetect_KL25Z/#4f11ae3737c7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 18 05:48:12 2014 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+#include "PinDetect.h"
+#include "rtos.h"
+
+const int BUZZERS = 3;
+const int LETTERS = 27;
+
+Serial pc(USBTX, USBRX);
+PinDetect buttons [3] = {
+    PinDetect(D15),
+    PinDetect(D14),
+    PinDetect(D13)
+};
+
+// Note: there are only THREE PWMs on the board. So this is all we can use
+// for this particular method of sound output.
+PwmOut buzzers [3] = {
+    PwmOut(D0),
+    PwmOut(D2),
+    PwmOut(D3)
+};
+// Periods of notes in microseconds
+int notePeriods [8] = {
+    3818,   // C4
+    3412,   // D4
+    3030,   // E4
+    2895,   // F4
+    2551,   // G4
+    2273,   // A4
+    2024,   // B4
+    10000000 // inaudible 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}
+};
+
+void playAllChords(void) {
+    for (int i = 0; i < LETTERS; i++) {
+        int *chord = chords[i];
+        for (int j = 0; j < BUZZERS; j++) {
+            int noteIndex = chord[j];
+            if (noteIndex == 7) {
+                buzzers[j] = 0;
+            }
+            else {
+                buzzers[j] = .5f;
+                int period = notePeriods[noteIndex];
+                buzzers[j].period_us(period);
+            }
+        }
+        wait_ms(1000);
+    }
+}
+
+int main() {
+    // Initialize all duty cycles to off, so we hear nothing.
+    for (int i = 0; i < BUZZERS; i++) {
+        buzzers[i] = 0.0f;
+    }
+    pc.printf("%c\n", 97);
+    // playAllChords();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Sep 18 05:48:12 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#631c0f1008c3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 18 05:48:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwmout.bld	Thu Sep 18 05:48:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file