stepper mottor for pumps

Dependencies:   mbed

Revision:
2:5b26538ab9ab
Parent:
1:8431b042a2eb
--- a/main.cpp	Sun Jun 19 21:32:08 2016 +0000
+++ b/main.cpp	Mon Jun 20 13:44:12 2016 +0000
@@ -10,19 +10,13 @@
 
 Ping Pinger(p30);
 Serial pc(USBTX, USBRX);
-//TextLCD lcd(p19, p20, p21, p22, p23, p24); // rs, e, d4-d7
 
-//DigitalOut myled(LED1);
     int PULL = 1;
     int PUSH = 0;
     int SALT = 1;
     int PURE = 0;
     int PREVIOUS_DIRECTION_SALT = -1;
     int PREVIOUS_DIRECTION_PURE = -1;
-    //int POSITION_SALT = 14;
-    //int POSITION_PURE = 27;
-    //int MAX = 35;
-    //int MIN = 0; 
     
     DRV8825 stpr_mtr(p21, p27, p28, p29, p22, p23);
     DRV8825 stpr_mtr2(p24, p27, p28, p29, p25, p26);
@@ -47,8 +41,8 @@
 
 void add_water(int type, double mililiters, int DIRECTION){
         
-    int MOVEMENT = 4600; //constant for 1 mL
-    double STEP_EXTRA = 3000; //for the other mL's
+    int MOVEMENT = 4000; //constant for 1 mL
+    double STEP_EXTRA = 4700; //for the other mL's
             
         //accelerate
         for (int i = 25; i < MAX_SPEED; i+=20) {    
@@ -59,19 +53,13 @@
         } 
     
         //fix the changing of directions for pure
-        if (type == PURE){       
-            //mililiters = mililiters * 2.0;    
-           if (PREVIOUS_DIRECTION_PURE != DIRECTION)
-              mililiters = mililiters + 1.0;
+        if (type == PURE && PREVIOUS_DIRECTION_PURE != DIRECTION){          
+            mililiters = mililiters + 1.0;
         }    
     
         //fix the changing of directions for salt
-        if (type == SALT){       
-          //mililiters = mililiters * 2.0;
-          if (PREVIOUS_DIRECTION_SALT != DIRECTION)
-             mililiters = mililiters + 1.0;
-         //if (PREVIOUS_DIRECTION_SALT == PULL)
-               //mililiters = mililiters + 0.5;      
+        if (type == SALT && PREVIOUS_DIRECTION_SALT != DIRECTION){
+             mililiters = mililiters + 1.0;  
         }    
 
         //move with constant speed
@@ -80,11 +68,8 @@
                 stpr_mtr.settings(1/MICROSTEPS_PER_STEP, DIRECTION, MAX_SPEED);
             else
                 stpr_mtr2.settings(1/MICROSTEPS_PER_STEP, DIRECTION, MAX_SPEED);   
-            
-            //if ((i - MOVEMENT) % STEP_EXTRA == 0 && !proximity_ok())
-              //  break;
         }
-        
+   
         //de-accelerate
         for (int i = MAX_SPEED; i > 0; i-=20) {    
             if (type == SALT)
@@ -102,59 +87,29 @@
 }
 
 int main() {
-    
-    //add_water(PURE, -1, PUSH);
-    //add_water(SALT, -1, PUSH);
-    
-    //if(proximity_ok()){
-    //add_water(SALT, 1, PULL);
-        //lcd.printf(" GO");
-        //add_water(SALT, 2, PUSH);
-        add_water(PURE, 2.0, PUSH);
-        wait(2);
-        add_water(PURE, 2.0, PULL);
-        wait(2);
-        add_water(PURE, 2.0, PUSH);
-        wait(2);
-        add_water(PURE, 2.0, PULL);
-        wait(2);
-        add_water(PURE, 2.0, PUSH);
-        wait(2);
-        add_water(PURE, 2.0, PULL);
-        //add_water(SALT, 2, PULL);
-        /*
-        wait(2);
-        add_water(SALT, 1, PULL);
-        wait(2);
-        add_water(SALT, 2, PUSH);
-        wait(2);
-        add_water(SALT, 3, PULL);
-        //add_water(PURE, 1, PUSH);
-        //wait(2);
-        */
-    //}    
-    
-    /*
-    //add_water(SALT, 2, PULL);
-    if(proximity_ok()){
-        add_water(SALT, 2, PUSH);
-        wait(2);
-    }    
-    //add_water(SALT, 3, PULL);
-    if(proximity_ok()){
-        add_water(SALT, 3, PUSH);
-        wait(2);
-    }
-      
-        add_water(SALT, 2, PUSH);
-   
-    //add_water(PURE, 1, PULL);
-    //add_water(PURE, 1, PUSH);
-    //add_water(PURE, 2, PULL);
-    //add_water(PURE, 2, PUSH);
-    //add_water(PURE, 3, PULL);
-    //add_water(PURE, 3, PUSH);
-
-    */
-    
+        //initialize
+        wait(3); //turn the thing to pulling from reservoir
+        add_water(PURE, 20.0, PULL); //20
+        wait(3); //turn the thing to pushing to glass
+        add_water(PURE, 20.0, PUSH); //19.5 
+        wait(3); //turn the thing to pulling from reservoir
+        add_water(PURE, 20.0, PULL); //20
+        wait(3); //turn the thing to pushing to glass
+        add_water(PURE, 20.0, PUSH); //19
+        wait(3); //turn the thing to pulling from reservoir
+        add_water(PURE, 25.0, PULL); //20
+        //done
+        
+        //initialize
+        wait(3); //turn the thing to pulling from reservoir
+        add_water(SALT, 20.0, PULL); //20
+        wait(3); //turn the thing to pushing to glass
+        add_water(SALT, 20.0, PUSH); //19.5 
+        wait(3); //turn the thing to pulling from reservoir
+        add_water(SALT, 20.0, PULL); //20
+        wait(3); //turn the thing to pushing to glass
+        add_water(SALT, 20.0, PUSH); //19
+        wait(3); //turn the thing to pulling from reservoir
+        add_water(SALT, 25.0, PULL); //20
+        //done
 }