![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
slave
Fork of ESE350-Whack-a-Mole-Slave by
Diff: WhackAMole.cpp
- Revision:
- 1:59384b12aa98
- Parent:
- 0:ddc820578cb0
- Child:
- 2:77c9b15d79c0
- Child:
- 3:bd90ff182f98
diff -r ddc820578cb0 -r 59384b12aa98 WhackAMole.cpp --- a/WhackAMole.cpp Wed Mar 20 19:05:36 2013 +0000 +++ b/WhackAMole.cpp Tue Oct 20 18:09:41 2015 +0000 @@ -5,7 +5,7 @@ // RF tranceiver to link with handheld. MRF24J40 mrf(p11, p12, p13, p14, p21); - +AnalogIn light_sensor(p20); // LEDs you can treat these as variables (led2 = 1 will turn led2 on!) DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -90,24 +90,18 @@ while(true) { //Try to receive some data - rxLen = rf_receive(rxBuffer, 128); - if(rxLen > 0) { - //Toggle the Led - led1 = led1^1; - pc.printf("Received: %s\r\n", rxBuffer); - } - //Send some data every second - if(timer.read_ms() >= 1000) { - //Reset the timer to 0 - timer.reset(); - // Toggle LED 2. - led2 = led2^1; - //Add to the buffer. You may want to check out sprintf - strcpy(txBuffer, "Jeff is the best TA!"); - //Send the buffer - rf_send(txBuffer, strlen(txBuffer) + 1); - pc.printf("Sent: %s\r\n", txBuffer); - } + while(true){ + rxLen = rf_receive(rxBuffer, 128); + pc.printf("Received: %s\r\n", rxBuffer); + if(strcmp("activate_1", txBuffer)) { + break; + } + } + led1=1; + while (light_sensor*100>10); + led1=0; + strcpy(txBuffer, "finished_1"); + rf_send(txBuffer, strlen(txBuffer)); } }