Juan Carlos Suárez Barón / Mbed 2 deprecated L298

Dependencies:   mbed TextLCD1

Fork of L298 by Hernán Maya

Files at this revision

API Documentation at this revision

Comitter:
juanitoinig84
Date:
Fri Jul 01 03:38:09 2016 +0000
Parent:
1:c83539e7f8a0
Child:
4:28c613b8345b
Commit message:
Segunda versi?n

Changed in this revision

TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Jul 01 03:38:09 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/satelite/code/TextLCD1/#f075d2b4ac2d
--- a/main.cpp	Wed Jun 22 21:31:17 2016 +0000
+++ b/main.cpp	Fri Jul 01 03:38:09 2016 +0000
@@ -1,4 +1,14 @@
 #include "mbed.h"
+#include "TextLCD.h"
+
+# define ON  1
+# define OFF 0
+////////////////********Definitions***********///////
+DigitalOut led_red(LED_RED);
+DigitalOut led_green(LED_GREEN);
+DigitalOut led_blue(LED_BLUE);
+
+Serial pc(USBTX, USBRX);
 
 DigitalOut in1(PTC3);
 DigitalOut in2(PTC2);
@@ -7,40 +17,80 @@
 DigitalOut in3(PTD1);
 DigitalOut in4(PTD2);
 PwmOut     enb(PTD3);
+////////////////*************************//////////////
 
+////////////****Prototype Functions*******//////////
+void stop1(void);
+void stop2(void);
+void turnLeft1(void);
+void turnLeft2(void);
+void turnRight1(void);
+void turnRight2(void);
+////////////////*************************//////////////
 
 int main()
 {
+    pc.baud(115200);
+    pc.printf("Peristaltic pumps FRDM-K64F board.\n");
     while (true) {
     /////******MOTOR 1****////
-        // Detiene el motor
-        in1 = 0; 
-        in2 = 0;
-        wait(0.5f);
-        // Gira en sentido 1 con velocidad 50%
-        in1 = 1;
-        in2 = 0;
-        ena.write(0.50f);
-        wait(0.5f);
-        // Gira en sentido 2 con velocidad 100%
-        in1 = 0;
-        in2 = 1;
-        ena.write(1.00f);
-        wait(0.5f);
+       
+        stop1();                     //Stop motor
+        wait(2.0f);
+        turnLeft1();                // Gira en sentido 1
+        ena.write(0.50f);           //Velocidad 50%
+        wait(2.0f);
+       turnRight1();                // Gira en sentido 2 
+        ena.write(1.00f);           // Velocidad 100%
+        wait(2.0f);
         
     /////******MOTOR 2****////
-       in3 = 0; 
-        in4 = 0;
-        wait(0.5f);
-        // Gira en sentido 1 con velocidad 50%
-        in3 = 1;
-        in4 = 0;
-        ena.write(0.50f);
-        wait(0.5f);
-        // Gira en sentido 2 con velocidad 100%
-        in3 = 0;
-        in4 = 1;
-        ena.write(1.00f);
+      stop2();
+        wait(2.0f);
+        turnRight2();              // Gira en sentido 1 
+        enb.write(0.50f);          //velocidad 50%
+        wait(2.0f);
+        turnLeft2();                // Gira en sentido 2
+        enb.write(1.00f);           //velocidad 100%
         wait(0.5f);
     }
+}
+
+///////////////***********FUNCTIONS***********************//////////////
+void stop1(void) {
+ led_red = ON;
+  in1 = OFF; 
+  in2 = OFF;
+  //wait(0.5f);
+}
+
+void stop2(void) {
+ led_green = ON;
+  in3 = OFF; 
+  in4 = OFF;
+  //wait(0.5f);
+}
+
+void turnLeft1() {
+    led_blue = ON;
+    in1 = OFF;
+    in2 = ON;      
+}
+
+void turnLeft2() {
+    led_green = ON;
+    in3 = OFF;
+    in4 = ON;
+}
+
+void turnRight1() {
+    led_red = ON;
+    in1 = ON;
+    in2 = OFF;   
+}
+
+void turnRight2() {
+ led_green = ON;
+  in3 = ON;
+  in4 = OFF;    
 }
\ No newline at end of file