slave

Dependencies:   mbed

Fork of ESE350-Whack-a-Mole-Slave by ESE519

Files at this revision

API Documentation at this revision

Comitter:
shibulal
Date:
Thu Oct 22 02:16:09 2015 +0000
Parent:
2:77c9b15d79c0
Commit message:
final

Changed in this revision

WhackAMole.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 77c9b15d79c0 -r fc72ba6a2048 WhackAMole.cpp
--- a/WhackAMole.cpp	Wed Oct 21 01:30:55 2015 +0000
+++ b/WhackAMole.cpp	Thu Oct 22 02:16:09 2015 +0000
@@ -87,26 +87,44 @@
 
     //Start the timer
     timer.start();
+    bool time_out;
+
 
     while(true) {
         //Try to receive some data
-        
+        time_out=false;
         while(true){
             rxLen = rf_receive(rxBuffer, 128); 
             if (rxLen>0){
                 pc.printf("Received: %s\r\n", rxBuffer);   
                 //strcpy(rxBuffer,"");
-                if(!strcmp("activate_1", rxBuffer)) {
-                break;
-                }
-            } 
-
+                if(!strcmp("activate_2", rxBuffer)) {
+                    break;
+                    }
+                else if (!strcmp("check_2", rxBuffer)){
+                        strcpy(txBuffer, "confirm_2");
+                        rf_send(txBuffer, strlen(txBuffer)+1);
+                        pc.printf("Sent: %s\r\n", txBuffer);
+                    }
+                } 
             }
         led1=1;
-        while (light_sensor*100>10.0);
+        while (light_sensor*100>10.0){
+            rxLen = rf_receive(rxBuffer, 128); 
+            if (rxLen>0){
+                pc.printf("Received: %s\r\n", rxBuffer);   
+                //strcpy(rxBuffer,"");
+                if(!strcmp("time_out_2", rxBuffer)) {
+                    time_out=true;
+                    break;
+                    }
+                } 
+            }
         led1=0;
-        strcpy(txBuffer, "finished_1");
-        rf_send(txBuffer, strlen(txBuffer)+1);
-        pc.printf("Sent: %s\r\n", txBuffer);
+        if (!time_out){
+            strcpy(txBuffer, "finished_2");
+            rf_send(txBuffer, strlen(txBuffer)+1);
+            pc.printf("Sent: %s\r\n", txBuffer);
+        }
     }
 }