Paulo Gonçalves / Mbed 2 deprecated objeto_motor_de_passo

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
pjgoncalvesf
Date:
Tue Apr 28 17:10:06 2015 +0000
Commit message:
biblioteca de motor de passo v0.1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
motor_de_passo/motor_de_passo.cpp Show annotated file Show diff for this revision Revisions of this file
motor_de_passo/motor_de_passo.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 28 17:10:06 2015 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+#include "motor_de_passo.h"
+
+int main() {
+    Motor_de_passo M1 (PTC9,PTA5,PTC8,PTA4);
+    M1.vel = 0.5;
+    M1.n_passos=400;
+    
+    M1.girar(-360); 
+    
+    while(1){
+       }
+}   
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Apr 28 17:10:06 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor_de_passo/motor_de_passo.cpp	Tue Apr 28 17:10:06 2015 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+#include "motor_de_passo.h"
+
+const int Motor_de_passo::motor[] =   {0x8,0xC,0x4,0x6,0x2,0x3,0x1,0x9};
+Motor_de_passo::Motor_de_passo(PinName pino1, PinName pino2, PinName pino3, PinName pino4)
+     : _passos(pino1,pino2,pino3,pino4)
+     {
+        // motor[] 
+    }
+
+void Motor_de_passo::motor1(){
+   if (aux == 0){
+        _passos = 0x0f&motor[1];
+        aux = positivo?1:7;
+    } else if (aux == 1){
+        _passos = 0x0f&motor[2];
+        aux = positivo?2:0;
+    } else if (aux == 2){
+        _passos = 0x0f&motor[3];
+        aux = positivo?3:1;
+    } else if (aux == 3){
+        _passos = 0x0f&motor[4];
+        aux = positivo?4:2;
+    }else if (aux == 4){
+        _passos = 0x0f&motor[5];
+        aux = positivo?5:3;
+    } else if (aux == 5){
+        _passos = 0x0f&motor[6];
+        aux = positivo?6:4;
+    } else if (aux == 6){
+        _passos = 0x0f&motor[7];
+        aux = positivo?7:5;
+    } else if (aux == 7){
+        _passos = 0x0f&motor[0];
+        aux = positivo?0:6;
+                     
+    }
+ }
+ 
+ void Motor_de_passo::flip() {
+    motor1();
+    i=i+1; 
+    if (j==i){
+           flipper.detach();
+        }
+}
+
+void Motor_de_passo::girar (float graus) 
+     {
+        aux=0;
+        positivo = graus<0? false: true;
+        i=0;
+        float tempo = (1.0f/((n_passos)*(vel)));
+        flipper.attach(this,&Motor_de_passo::flip, tempo);
+       
+       j=abs(graus)/(360.0f/n_passos);
+       
+     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor_de_passo/motor_de_passo.h	Tue Apr 28 17:10:06 2015 +0000
@@ -0,0 +1,24 @@
+#ifndef motor_de_passo // funcionou sem 
+#define motor_de_passo // funcionou sem 
+#include "mbed.h"
+
+class Motor_de_passo{
+    public:
+     Motor_de_passo(PinName pino1, PinName pino2, PinName pino3, PinName pino4);
+     float vel;
+     int n_passos;
+     void girar(float graus);
+     void motor1();
+     void flip();
+     
+    private:
+     BusOut _passos;
+     int j;
+     Ticker flipper;
+    static const int motor[8];
+    int aux;
+    int i;
+    int positivo;
+    
+     };
+#endif // funcionou sem 
\ No newline at end of file