joy

Dependencies:   mbed USBDevice USBJoystick_

Revision:
2:d9f806076779
Parent:
0:4badd5dcda2b
diff -r 1ec4525ad0cf -r d9f806076779 main.cpp
--- a/main.cpp	Sun Jul 25 18:05:13 2021 +0000
+++ b/main.cpp	Sun Aug 01 17:36:27 2021 +0000
@@ -6,7 +6,6 @@
 DigitalOut myled3(LED3);
 DigitalOut myled4(LED4);
 
-InterruptIn mybutton(USER_BUTTON);
 InterruptIn ppm(D7);
 USBJoystick joystick;
 double tempo = 0.3; // LED blinking delay
@@ -15,7 +14,7 @@
 
 volatile int period;
 
-int8_t channels[9] ={0,0,0,0,0,0,0,0,0};
+int16_t channels[9] ={0,0,0,0,0,0,0,0,0};
 uint8_t curChannel = 0;
 bool done=false;
 
@@ -27,82 +26,61 @@
     timer.reset();
     if(period > 3000)
     {
-        done = true;
         curChannel = 0;
+        done=true;
         return;
     }
     
-    period -= 1050;
-    if(period  < 0)
-        period = 0;
-    if(period > 1100)
-        period = 1100;
-        
-    period*=255;
-    period/=1100;
-    int buf = period;
+    period -= 1580;
+ /*   if(period  < -550)
+        period = -550;
+    if(period > 550)
+        period = 550;
+  */      
+ /*   period*=255;
+    period/=1100;*/
+/*    int buf = period;
     int val = buf-128;
     if(val < -127)
         val = -127;
     if(val > 128)
         val = 128;
     channels[curChannel] = -val;
+    */
+    if(curChannel < 9)
+        channels[curChannel] = -period; 
     curChannel++;
     myled1=1;
     myled2=0;
 }
 
-// Change LEDs blinking frequency
-void change_blinking_frequency() {
-    if (tempo == 0.3) // If leds have low frequency
-        tempo = 0.1;  // Set the fast frequency
-    else              // If leds have fast frequency
-        tempo = 0.3;  // Set the low frequency
-}
-
 int main() {
     // All LEDs are OFF
     myled1 = 0;
     myled2 = 0;
     myled3 = 0;
     myled4 = 0;
+    ppm.rise(&rise);
     timer.start();
-    ppm.rise(&rise);
 
-    // Change LEDs blinking frequency when button is pressed
-    mybutton.fall(&change_blinking_frequency);
-    ppm.rise(&rise);
-
-uint32_t count = 0;
-    int8_t thr = 0;
-    int8_t rudder = 0;
-    int8_t x=0;
-    int8_t y=0;
+    uint32_t count = 0;
+    int16_t thr = 0;
+    int16_t rudder = 0;
+    int16_t x=0;
+    int16_t y=0;
 
     while(1) {
-        wait(0.001);  // wait tempo
-
-     /**
-       * Write state of the joystick
-       *
-       * @param t throttle position
-       * @param r rudder position         
-       * @param x x-axis position
-       * @param y y-axis position
-       * @param buttons buttons state
-       * @param hat hat state 0 (up), 1 (right, 2 (down), 3 (left) or 4 (neutral)
-       * @returns true if there is no error, false otherwise
-       */
-
-    if(done)
-    {
-        thr = channels[0];
-        rudder = channels[1];
-        x = channels[2];
-        y = channels[3];
-        done = 0;
-    }
-    joystick.update(thr, rudder, x, y, count, 0);
+       // wait(1.000);  // wait tempo
+      
+        if(done)
+        {
+            thr = channels[0];
+            rudder = channels[1];
+            x = channels[2];
+            y = channels[3];
+            done = 0;
+            joystick.update(thr, rudder, x, y, channels[4], channels[5], channels[6], channels[7], count&0, 0);
+        }
 
         count++;
     }