slave

Dependencies:   mbed music2

Files at this revision

API Documentation at this revision

Comitter:
TylerMuch
Date:
Wed Feb 19 01:02:05 2014 +0000
Commit message:
done

Changed in this revision

main.cpp 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
music.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r acf1f01685d5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 19 01:02:05 2014 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "music.h"
+
+float song[];
+float beat[];
+
+I2CSlace i2c(p9, p10);
+PwmOut spkr(p26);
+
+
+
+int main() {
+    i2c.address(0x42);
+    while(1) 
+    {
+        int recv = i2c.receive();
+        unsigned char note = i2c.read();
+        switch(recv) {
+            case I2CSlave::WriteAddressed:
+                // receiving song from master
+                if(note == 0xFF) spkr = 0;
+                spkr.period(1/notes[note]);
+                spkr = 0.5f;
+                break;
+            case I2CSlave::ReadAddressed: 
+                // sending song to master 
+                for(int i = 0; i < sizeof(...); i++)
+                {
+                    note = song[i];
+                    i2c.write(note);
+                    spkr = 0.5f;
+                    spkr.period(1/notes[note]);
+                    wait(beat[i]);   
+                }
+                spkr = 0;
+                break;
+        }
+    }
+}
diff -r 000000000000 -r acf1f01685d5 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Feb 19 01:02:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file
diff -r 000000000000 -r acf1f01685d5 music.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/music.lib	Wed Feb 19 01:02:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/TylerMuch/code/music2/#ff3131de444e