E

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
fabeltranm
Date:
Wed Mar 21 01:32:33 2018 +0000
Parent:
0:2890f9a09e85
Commit message:
bool cw

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
stepmotor.cpp Show annotated file Show diff for this revision Revisions of this file
stepmotor.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Mar 20 23:49:10 2018 +0000
+++ b/main.cpp	Wed Mar 21 01:32:33 2018 +0000
@@ -5,7 +5,7 @@
 Serial pc(USBTX,USBRX);
 int main() {
     uint32_t speed=1500;
-    uint8_t cw=1;
+    bool cw=true;
     while(1)
     {
         smotor1.set_speed(speed);
@@ -15,7 +15,7 @@
         
         smotor1.step(4096,cw);
         
-        cw=~cw &(0x01);
+        cw^=cw;
         speed=speed+200;
         if (speed > 10000)speed =1500;
         wait(1);
--- a/stepmotor.cpp	Tue Mar 20 23:49:10 2018 +0000
+++ b/stepmotor.cpp	Wed Mar 21 01:32:33 2018 +0000
@@ -52,7 +52,7 @@
     return motorSpeed; // 
 }
 
-void stepmotor::step(uint32_t num_steps, uint8_t cw) {
+void stepmotor::step(uint32_t num_steps, bool cw) {
 // funcion para mover el motor N pasos CW o CCW   
 // num_steps  número de paso que da el motor 
 // cw =True  para dirección en sentido del reloj 
@@ -60,8 +60,8 @@
    
     uint32_t count=num_steps ;
     while(count){
-        if (cw==1)   nstep++;     
-        if (cw==0)  nstep--;
+        if (cw)   nstep++;     
+        else      nstep--;
         if (nstep>7) nstep=0;
         if (nstep<0) nstep=7;
         move();
--- a/stepmotor.h	Tue Mar 20 23:49:10 2018 +0000
+++ b/stepmotor.h	Wed Mar 21 01:32:33 2018 +0000
@@ -17,7 +17,7 @@
 public:
  
     stepmotor(PinName in1, PinName in2, PinName in3, PinName in4); 
-    void step(uint32_t num_steps,uint8_t cw);
+    void step(uint32_t num_steps,bool cw);
     void set_speed(int speed);
     uint32_t get_speed();
 private: