For master node of whack a mole program

Dependencies:   mbed

Fork of ESE350-Whack-a-Mole by Eric Berdinis

Revision:
4:76adb6c7e67d
Parent:
3:4f09529d391b
diff -r 4f09529d391b -r 76adb6c7e67d whack_master.cpp
--- a/whack_master.cpp	Thu Oct 22 00:18:56 2015 +0000
+++ b/whack_master.cpp	Thu Nov 19 08:11:52 2015 +0000
@@ -102,7 +102,8 @@
         uint8_t channel;
         
         //Set the Count to 10
-        int count = 0;
+        int count,n = 0;
+        int dont_set_channel = 0;
         float begin = 0;
         float end   = 0;
         float diff  = 0;
@@ -121,14 +122,24 @@
             
             //Calculate random number
             //srand(time(0));
-            channel = (rand()%(slaves)) + 14; //set to minimum channel 
+            channel = (rand()%(slaves)) + 14;  
             //channel = 15;
             
+            //Check for channel of the mole if a light was missed 
+            while(dont_set_channel == channel){
+                channel = (rand()%(slaves)) + 14; //set to minimum channel     
+            }
+            
+            //dont_set_channel= 0;
+                       
             //Set the Channel to the random node selected
             mrf.SetChannel(channel);
             
             //Send message to the random slave and start timer
-            strcpy(txBuffer, "set");
+            char num = n;
+            char* numptr;
+            numptr = #
+            strcpy(txBuffer, numptr);
             rf_send(txBuffer, strlen(txBuffer) + 1);
             //Switch on the Led when sending data
             led2 = 1;
@@ -158,10 +169,17 @@
                     if(strcmp (yes,rxBuffer) == 0){
                         pc.printf("pressed\n");
                         count++;
+                        n++;
+                        //strcpy(txBuffer, "d"); //send d to decrement the time on slaves end
+                        dont_set_channel = 0;
                     }
                     //If it was not pressed - dont alter the count
                     else if(strcmp (no,rxBuffer) == 0){
                         pc.printf("Not pressed\n");
+                        //strcpy(txBuffer, "s");
+                        tdiff += 3; // Penalty of 3 seconds
+                        dont_set_channel = channel; // if there was no press do not send on light on this channel again
+                       
                     }
                         
                     break;