Project for playing a song on 2 meeds sending notes over I2C

Dependencies:   C12832 mbed

Revision:
4:bd0675c58f5e
Parent:
3:eb63ba24e2bb
Child:
5:432203c226ed
--- a/main.cpp	Thu Feb 13 20:34:35 2014 +0000
+++ b/main.cpp	Thu Feb 13 21:21:44 2014 +0000
@@ -13,24 +13,22 @@
 DigitalIn down(p12);
 BusOut leds(LED1,LED2,LED3,LED4);
 
+#ifdef MASTER
 I2C i2cPort(p9,p10);
+#endif
+#ifdef SLAVE
+I2CSlave slave(p9,p10);
+#endif
 char note;
 char length;
-const int masterAddress = 0x61;
-const int slaveAddress = 0x60;
+const int slaveAddress = 0x42;
+int received = 0;
 
 int main()
 {
-    float p1Voltage = 0;
-    float p2Voltage = 0;
-    float blueDC = 1;
-    red.period(0.001);
-    green.period(0.001);
-    blue.period(0.001);
-    red=1;
-    green=1;
-    blue=1;
-    
+#ifdef SLAVE
+    slave.address(slaveAddress);
+#endif
     lcd.cls();
     lcd.printf("hello world");
     
@@ -58,14 +56,41 @@
 #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
                 
             }
-#elif SLAVE
-
+#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
         }
     }