Seeker of Truth , / Mbed 2 deprecated slave_1

Dependencies:   mbed

Fork of slave_1 by sakthi priya amirtharaj

Revision:
0:ee332448b24c
Child:
1:afb4a0df7ff1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 06 13:03:55 2014 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+
+#define interrupt D9
+                    
+
+I2CSlave slave(D14,D15);                       
+Serial pc(USBTX,USBRX);
+InterruptIn m2s_interrupt(interrupt);
+
+void execute_command(char* cmd);
+
+void read_command()
+{
+    bool read_loop = true;
+    printf("\nEntered slave \n");
+    char *command = new char;         
+    while(read_loop){
+                slave.address(0x20);
+                int slave_status =1;
+                slave_status=slave.read(command,1);
+                if(!slave_status){
+                    printf("read %c from master\n\r",*command);
+                    read_loop = false;}
+                    }
+    execute_command(command);   //assumed command is very important
+    printf("\n done \n \r");
+    delete command;
+}
+
+void execute_command(char* cmd)
+{
+    switch(*cmd)
+    {
+        case '0':printf("\n command 0 executed \n\r");
+        break;
+        case '1':printf("\n command 1 executed \n\r");
+        break;
+        case '2':printf("\n command 2 executed \n\r");
+        break;
+        case '3':printf("\n command 3 executed \n\r");
+        break;
+        case '4':printf("\n command 4 executed \n\r");
+        break;
+    }
+}
+    
+
+                   
+int main(){
+   
+    printf("waiting for commands from master");
+    m2s_interrupt.rise(&read_command);
+    while(1)
+    {
+        ;
+    }
+    //write2slave();
+    }
\ No newline at end of file