NMLAB / Mbed 2 deprecated XYZ_Joystick_PWM

Dependencies:   SoftPWM USBDevice mbed

Revision:
3:7a2b052c95a3
Parent:
2:31a9ee6d066d
Child:
4:58ae811bff73
--- a/main.cpp	Fri Apr 17 04:46:12 2015 +0000
+++ b/main.cpp	Fri Apr 17 04:53:56 2015 +0000
@@ -18,7 +18,7 @@
 #define MAX_LOGIC  10000   // Full-deflection Max Range
 #define MIN_LOGIC  0       // Full-deflection Min Range
 
-#define SWITCH_LEVELS  5  // # of possible levels
+#define SWITCH_LEVELS  5  // # of possible levels  . MUST BE ODD. Median value is OFF
 #define FWD            1
 #define REV            0
 
@@ -26,8 +26,8 @@
 
 //NOTE: Period MUST be defined 1st, them DC. 
 
-float Period_Array [SWITCH_LEVELS] = {0.01, 0.1,  100.0, 0.1, 0.01};    // Period Corresponding to 10, 100, 0,  100, 10 Hz
-uint16_t SpeedThreshold = MAX_LOGIC / SWITCH_LEVELS;
+float Period_Array [SWITCH_LEVELS] = {0.01, 0.1,  100.0, 0.1, 0.01};    // Period Corresponding to 10, 100, 0,  100, 10 Hz MUST be odd. 
+uint16_t SpeedThreshold = MAX_LOGIC / SWITCH_LEVELS; 
 
 uint16_t X_Speed = 4;
 uint16_t Y_Speed = 4;
@@ -56,12 +56,12 @@
         
         Z_Speed = (uint16_t) (Z_Axis.read() * MAX_LOGIC) / (SpeedThreshold + SpeedThreshold /  SWITCH_LEVELS);
         
-       if (X_Speed > 2) {X_Direction = FWD;}
-       if (X_Speed < 2) {X_Direction = REV;}
-       if (Y_Speed > 2) {Y_Direction = FWD;}
-       if (Y_Speed < 2) {Y_Direction = REV;}
-       if (Z_Speed > 2) {Z_Direction = FWD;}
-       if (Z_Speed < 2) {Z_Direction = REV;}
+       if (X_Speed > (SWITCH_LEVELS / 2)) {X_Direction = FWD;}
+       if (X_Speed < (SWITCH_LEVELS / 2)) {X_Direction = REV;}
+       if (Y_Speed > (SWITCH_LEVELS / 2)) {Y_Direction = FWD;}
+       if (Y_Speed < (SWITCH_LEVELS / 2)) {Y_Direction = REV;}
+       if (Z_Speed > (SWITCH_LEVELS / 2)) {Z_Direction = FWD;}
+       if (Z_Speed < (SWITCH_LEVELS / 2)) {Z_Direction = REV;}