Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Revision:
23:07a368f2cdb1
Parent:
19:384642f39496
Child:
25:9751619fa030
--- a/Stepper_Motor/STEPPER_MOTOR.cpp	Sat Feb 16 12:43:26 2019 +0000
+++ b/Stepper_Motor/STEPPER_MOTOR.cpp	Sat Feb 16 15:19:21 2019 +0000
@@ -9,144 +9,67 @@
 }
 
 STEPPER_MOTOR::~STEPPER_MOTOR(){}   //Destructor
+
+void STEPPER_MOTOR::Pause_Code()
+{
+    _Pause_Code = 1;   
+}
+void STEPPER_MOTOR::Unpause_Code()
+{
+    _Pause_Code = 0;   
+}
 float STEPPER_MOTOR::Get_Turns()
 {
     return (_Steps_Done /50);
 }
 void STEPPER_MOTOR::Rotate_Steps(int Steps)
-{
-         #define STIME    1000
-         
-         Steps = Steps*50;
-         //int correctionfactor;
-         //int timeofturn=correctinfactor*speed;
-         _Steps_Done = 0;
-         //int mystep=0;
-         //printf("START!!! step value is=%d\n\r",mystep);
-         for(int x =0 ; x <= Steps; x++)
-         {
-              //printf("FOR LOOP! step value is=%d  %d\n\r",mystep,x);
-                   this->pin1 = 0;
-                   this->pin2 = 1;
-                   this->pin3 = 0;
-                   this->pin4 = 1;
-                   //mystep=1;
-                   Thread::wait(1);
-                   //wait_us(1000);
-              //printf("FOR LOOP! step value is=%d  %d\n\r",mystep,x);
-                   this->pin1 = 0;
-                   this->pin2 = 1;
-                   this->pin3 = 1;
-                   this->pin4 = 0; 
-                  //mystep=2;
-                   Thread::wait(1);
-                   //wait_us(1000);
-              //printf("FOR LOOP! step value is=%d  %d\n\r",mystep,x);
-                   this->pin1 = 1;
-                   this->pin2 = 0;
-                   this->pin3 = 1;
-                   this->pin4 = 0;
-                   //mystep=3;
-                    Thread::wait(1);
-                   //wait_us(1000);
-              //printf("FOR LOOP! step value is=%d  %d\n\r",mystep,x);
-                   this->pin1 = 1;
-                   this->pin2 = 0;
-                   this->pin3 = 0;
-                   this->pin4 = 1;
-                   //mystep=4;
-                    Thread::wait(1);
-                   //wait_us(1000);
-                   
-                   _Steps_Done = _Steps_Done +1;
- /*             printf("FOR LOOP! step value is=%d  %d\n\r",mystep,x);
-                   this->pin1 = 0;
-                   this->pin2 = 1;
-                   this->pin3 = 0;
-                   this->pin4 = 0; 
-                   mystep=5;
-                   wait_ms(0.6);
-              printf("FOR LOOP! step value is=%d  %d\n\r",mystep,x);
-                   this->pin1 = 1;
-                   this->pin2 = 1;
-                   this->pin3 = 0;
-                   this->pin4 = 0;
-                   mystep=6;
-                   wait_ms(0.6);
-              printf("FOR LOOP! step value is=%d  %d\n\r",mystep,x);
-                   this->pin1 = 1;
-                   this->pin2 = 0;
-                   this->pin3 = 0;
-                   this->pin4 = 0;
-                   mystep=7;
-                   wait_ms(0.6);
-             
-                   this->pin1 = 1;
-                   this->pin2 = 0;
-                   this->pin3 = 0;
-                   this->pin4 = 1;
-                   mystep=0;
-                   wait_ms(0.6);
-
-                   this->pin1 = 0;
-                   this->pin2 = 0;
-                   this->pin3 = 0;
-                   this->pin4 = 0;
-                   mystep=0;
-                   wait_ms(0.6);*/
-            }
+{    
+    Steps = Steps*50;
+    //int correctionfactor;
+    //int timeofturn=correctinfactor*speed;
+    _Steps_Done = 0;
+    //int mystep=0;
+    //printf("START!!! step value is=%d\n\r",mystep);
+    for(int x =0 ; x <= Steps; x++)
+    {
+        if(_Pause_Code == 0)
+        {
             this->pin1 = 0;
+            this->pin2 = 1;
+            this->pin3 = 0;
+            this->pin4 = 1;
+            Thread::wait(1);
+            this->pin1 = 0;
+            this->pin2 = 1;
+            this->pin3 = 1;
+            this->pin4 = 0; 
+            Thread::wait(1);
+            this->pin1 = 1;
+            this->pin2 = 0;
+            this->pin3 = 1;
+            this->pin4 = 0;
+            Thread::wait(1);
+            this->pin1 = 1;
             this->pin2 = 0;
             this->pin3 = 0;
-            this->pin4 = 0;
+            this->pin4 = 1;     
+            Thread::wait(1);  
+            _Steps_Done = _Steps_Done +1;
+        }
+        else if (_Pause_Code == 1)
+        {
+            printf("Stepper motor code paused\n");
+            while(_Pause_Code == 1)
+            {
+                Thread::wait(1);
+            }
+        }
+    }//End of for loop
+    this->pin1 = 0;
+    this->pin2 = 0;
+    this->pin3 = 0;
+    this->pin4 = 0;
 }
-                   
-                   /*
-             switch(mystep){ 
-               case 0:{
-                  
-                break;  
-               case 1:{
-                  
-               break;  
-               case 2: 
-                   
-               break;  
-               case 3: 
-                   
-               break;  
-               case 4: 
-                 
-               break;  
-               case 5: 
-                   
-               break;  
-                 case 6: 
-                 
-               break;  
-               case 7: 
-                  
-               break;  
-               default: 
-               
-               break;  
-             } 
-             
-             if(_dir){ 
-               _step++; 
-             }else{ 
-               _step--; 
-             } 
-             if(_step>7){ 
-               _step=0; 
-             } 
-             if(_step<0){ 
-               _step=7; 
-             } 
-             */
-             //wait_ms(1);
-    
-
 void STEPPER_MOTOR::Permanent_Rotate_clock_wise()
 {
     switch(_step){