Wii Nunchuk via RFM69HW to Duplo 9203 Remote Control Car Kit using ARM mbed on a FRDM-KL25Z

Dependencies:   CRC FastPWM RFM69 USBDevice WakeUp WiiChuk_compat mbed-rtos mbed tlc59108

Fork of wiiNunchuk_compat by Greg Brush

Revision:
15:8888e36afe43
Parent:
14:579137c8ceac
Child:
16:3490cdea4986
--- a/main.cpp	Tue Jun 28 10:33:10 2016 +0000
+++ b/main.cpp	Tue Jun 28 10:43:05 2016 +0000
@@ -290,7 +290,6 @@
 
 int main()
 {
-    WakeUp::calibrate();
     RtosTimer rx_snooze(&rx_snoozer, osTimerOnce, (void*)osThreadGetId());
 
 #ifndef USBSerial
@@ -341,10 +340,14 @@
     if (sender) {
         pc.printf("chuck attached\r\n");
         radio.initialize(FREQUENCY, NODE_ID, NETWORKID);
+        central_time.start();
     } else {
         pc.printf("chuck unavailable\r\n");
         radio.initialize(FREQUENCY, GATEWAY_ID, NETWORKID);
+        // only relevant to the receiver
         thread = new Thread(ir_thread);
+        rx_last_contact.start();
+        // these break the nunchuk
         wave = new float[i];
         int m = i-128;
         for(int k = 0; k < m; k++) {
@@ -355,8 +358,8 @@
             // LFO
             wave[127-k] = 1.0/(1400+200*sin(k/128.0*6.28318530717959));
         }
-        rx_last_contact.start();
-   }    
+        WakeUp::calibrate();
+   }
     radio.encrypt("0123456789054321");
     //radio.promiscuous(false);
     radio.setHighPower(true);
@@ -427,18 +430,18 @@
             if (R < 20) {
                 if (!central) {
                     pc.printf("central\r\n");
-                    central_time.start();
                     central = true;
                 }
+                if (n->C || n->Z)
+                    central_time.reset();
                 r = 1.0f;
                 g = 1.0f;
                 b = 1.0f;
             } else {
+                central_time.reset();
                 if (central) {
                     pc.printf("go %s\r\n", directions[direction]);
                     central = false;
-                    central_time.stop();
-                    central_time.reset();
                 }
                 R = R/20000;
                 float pal[8][3] = {