ping + display on

Dependencies:   DigitDisplay Motor PID Ping mbed millis

Fork of MainProgram_BaseBaru_20Feb by KRAI 2017

Revision:
36:5963c9a49485
Parent:
35:69a47b4cb3fc
Child:
37:67d54563af90
diff -r 69a47b4cb3fc -r 5963c9a49485 main.cpp
--- a/main.cpp	Tue Feb 14 14:50:59 2017 +0000
+++ b/main.cpp	Tue Feb 14 16:20:35 2017 +0000
@@ -62,7 +62,7 @@
 double last_error2 = 0, current_error2, sum_error2 = 0;
 float rpm, target_rpm = 8.0;
 float rpm2, target_rpm2 = 10.0;
-float pwmPowerUp        = 0.70;
+float pwmPowerUp        = 0.75;
 float pwmPowerDown      = -0.80;
 bool henti=false, hentis=false; 
  
@@ -91,6 +91,7 @@
 int case_joy;
 bool isLauncher = false;
 bool isReload = false;
+bool ReloadOn = false;
 int flagLauncher = 1;
 bool flag_Pneu = false;
 
@@ -326,20 +327,22 @@
         case (11) : 
         {
             // Power Screw Up
-            powerScrew.speed(pwmPowerUp);
+            //powerScrew.speed(pwmPowerUp);
+            ReloadOn = !ReloadOn;
             break;
         }
         case (12) : 
         {
             // Power Screw Down
-            powerScrew.speed(pwmPowerDown);
+            //powerScrew.speed(pwmPowerDown);
             break;
         }
         default : 
         {
             motorDpn.brake(1);
             motorBlk.brake(1);
-            if (!infraAtas)
+           // aktuator();
+         /*   if (!infraAtas)
             {
                 powerScrew.brake(1);
             }
@@ -352,11 +355,37 @@
             {
                 case_joy = 11;
                 aktuator();   
-            }
+            }*/
         }   
     } // End Switch
  }
  
+ void reloader()
+{
+    if(ReloadOn){
+        if(isReload){
+            powerScrew.speed(pwmPowerDown);
+            if(!limitBawah){
+                isReload = false;
+                ReloadOn = false;
+            }
+        }
+        else if(!limitTengah){
+            isReload = true;
+        }
+        else if(!infraAtas){
+            powerScrew.brake(1);
+        }
+        else{
+            powerScrew.speed(pwmPowerUp);
+        }
+    }
+    else{
+        powerScrew.brake(1);
+    }
+}
+ 
+ 
 void launcher()
 {
     if (isLauncher)
@@ -432,7 +461,8 @@
             case_joy = case_joystick();
             aktuator();
             launcher();
-            if ((millis()-previousMillis3 >= 700)&&(flag_Pneu)){
+            reloader();
+            if ((millis()-previousMillis3 >= 350)&&(flag_Pneu)){
                 pneumatik = 1;
                 flag_Pneu = false;
             }