Plays songs and changes LED Color

Dependencies:   C12832 mbed

Files at this revision

API Documentation at this revision

Comitter:
nadiyah
Date:
Thu Feb 13 22:47:05 2014 +0000
Parent:
0:c6da9c77286d
Commit message:
hard coded frequency; ;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c6da9c77286d -r 028b0f4df520 main.cpp
--- a/main.cpp	Wed Feb 12 17:47:09 2014 +0000
+++ b/main.cpp	Thu Feb 13 22:47:05 2014 +0000
@@ -4,7 +4,8 @@
 
 
 
-
+//#define MASTER
+#define SLAVE
 #include "mbed.h"
 PwmOut buzzer(p26);
 /*Table 4.3: Frequencies of notes used in tune
@@ -36,9 +37,34 @@
 
 C12832 lcd(p5, p7, p6, p8, p11);
 
-float frequency[]={392.00,659,659,587,659,392.00,392.00,440.00,440.00,523.25,440.00,440,392.00,392.00,392.00,659,659,587,659,392.00,392.00,440.00,440.00,392.00,261.63,659,587,261.63};
+char frequency[]={Gs4,E5,E5,D5,E5,GS4,GS4,A4,A4,C4,A4,A4,GS4,GS4,GS4,E5,E5,D5,E5,Gs4,Gs4,A4,A4,Gs4,C4,E5,D5,C4};
 float beat[]={1,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,1,1,1,1,2}; //beat array
+
+
+
+
+
+#ifdef MASTER
+I2C i2cPort(p9,p10);
+#endif
+#ifdef SLAVE
+I2CSlave slave(p9,p10);
+#endif
+char note;
+char length;
+const int slaveAddress = 0x42;
+int received = 0;
 int main() {
+    
+    
+    #ifdef SLAVE
+    slave.address(slaveAddress);
+#endif
+    lcd.cls();
+    lcd.printf("hello world");
+    
+    
+    
 while (1) {
     while(!JS){
 r=pot.read();
@@ -66,13 +92,55 @@
 
     
     
-    ///lcd
-
+#ifdef MASTER
+            if(up)
+            {//master sends its song to slave
+                i2cPort.start();
+                //send address
+                i2cPort.write(slaveAddress);
+                //send tempo (BPM)
+                //loop through song
+                i2cPort.write(6);
+//                for(char j=0;j<10;j++)
+//                {
+//                    //send frequency
+//                    i2cPort.write(j);
+//                    //play note
+//                    //wait length
+//                    wait(1);
+//                }
+//                //send stop code
+//                i2cPort.write(0xFF);
+                //close i2c port
+                i2cPort.stop();
+            }
+            else if(down)
+            {//slave should send it's song to master
+                
+            }
+#endif
+#ifdef SLAVE
+            received = slave.receive();
+            if(I2CSlave::ReadAddressed==received){//master is requesting slave song
+                
+            }
+            else if(I2CSlave::WriteAddressed==received){//master is sending its song
+                received = slave.read();
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Sent: %d",received);
+            }
+#endif
+        }
+    }
     
     
     
 
-}
+
+
+
+
 
 
     /* while(1){
@@ -85,6 +153,6 @@
     
     
 
-}
+
 
  
\ No newline at end of file