![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
For master node of whack a mole program
Fork of ESE350-Whack-a-Mole by
Diff: whack_master.cpp
- Revision:
- 2:73c0d4f0ff5c
- Parent:
- 1:691460a19f54
- Child:
- 3:4f09529d391b
--- a/whack_master.cpp Sat Oct 17 23:06:04 2015 +0000 +++ b/whack_master.cpp Sun Oct 18 21:08:07 2015 +0000 @@ -88,10 +88,10 @@ //Set the Count to 10 int count = 0; - int begin = 0; - int end = 0; - int diff = 0; - int tdiff = 0; + float begin = 0; + float end = 0; + float diff = 0; + float tdiff = 0; //Start the timer timer.start(); @@ -106,8 +106,8 @@ //Calculate random number //srand(time(0)); - //channel = (rand()%(slaves)) + 14; //set to minimum channel - channel = 15; + channel = (rand()%(slaves)) + 14; //set to minimum channel + //channel = 15; //Set the Channel to the random node selected mrf.SetChannel(channel); @@ -118,7 +118,7 @@ //Switch on the Led when sending data led2 = 1; printf("Sending signal to channel %u \n", channel); - begin = timer.read_us(); + begin = timer.read_ms(); //Wait for reply from the slave @@ -129,9 +129,9 @@ if(rxLen > 0) { //Calculate time difference - end = timer.read_us(); + end = timer.read_ms(); diff = end - begin; - tdiff += diff; + tdiff += (diff / 1000); //Switch off Led to indicate received data led2 = 0; @@ -157,6 +157,6 @@ }//end of while count - printf("Your did it in %d milliseconds\n",tdiff); + printf("Your did it in %f seconds\n",tdiff); }// end of main