ss

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
poresc
Date:
Mon Oct 26 06:28:16 2020 +0000
Commit message:
jj

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
diff -r 000000000000 -r b9f21a1a1fac main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 26 06:28:16 2020 +0000
@@ -0,0 +1,148 @@
+#include "string"
+#include "mbed.h"
+#include "sstream"
+Serial pc(USBTX,USBRX);
+DigitalIn pulso(PTC5);
+DigitalOut right(PTC7);
+DigitalOut left(PTC0);
+int rea,ns;
+string cadena;
+using namespace std;
+void velocidad(int a,float ad);
+PwmOut l1(PTB3),l2(PTC2);
+int selec;
+float cambio;
+float rpm;
+int i=0;
+int f=0;
+int m=0;
+
+//using namespace boost;
+float h;
+
+int main(){
+    
+    while(1){
+        if(pc.readable()){
+        cadena=pc.getc();
+        }
+        if(cadena=="0"){
+            h=0.0;
+            pc.printf("  pwm al 0 %.2f",h);
+            }
+       if (cadena=="1"){
+           
+            h=0.1;
+             pc.printf("   pwm al 10 %.2f",h);
+            }
+        if (cadena=="2"){
+            h=0.2;
+             pc.printf("    pwm al 20 %.2f",h);
+            }
+        if (cadena=="3"){
+            h=0.3;
+             pc.printf("    pwm al 30 %.2f",h);
+            }
+        if (cadena=="4"){
+            h=0.4;
+            //if(m!=2){
+          //  m=1;
+            //}
+             pc.printf("    pwm al 40 %.2f",h);
+            //if(m==0){
+                for(int j=0;j<=5;j++){
+                    if(pulso==1){
+                        i=i+1;
+                        
+                        
+                        }
+                        if(j==5){
+                            rpm=((i*60)/5)/6;
+                        }
+                 }
+               i=0;
+                     
+            }
+        if (cadena=="5"){
+            h=0.5;
+             pc.printf("    pwm al 50 %.2f",h);
+            }
+        if (cadena=="6"){
+            h=0.6;
+             pc.printf("    pwm al 60 %.2f",h);
+            }
+        if (cadena=="7"){
+            h=0.7;
+             pc.printf("    pwm al 70 %.2f",h);
+            }
+        if (cadena=="8"){
+            h=0.8;
+             pc.printf("    pwm al 80 %.2f",h);
+            }
+        if (cadena=="9"){
+            h=0.9;
+             pc.printf("   pwm al 90 %.2f",h);
+            }
+        if (cadena=="10"){
+            h=1;
+             pc.printf("    pwm al 100 %.2f",h);
+            }
+            if(cadena=="d"){
+                selec=1;
+                pc.printf("   derecha");
+            }
+            if(cadena=="i"){
+                selec=2;
+                pc.printf("   izquierda");
+                }
+                if(cadena=="n"){
+                selec=0;
+                pc.printf("  sin sentido");
+                }
+        wait(0.5);
+           // selec=1;
+          cambio=h;
+          
+        velocidad(selec,cambio);
+        /*if(
+        if(pulso==1){
+            i=i+1;
+            wait(0.2);
+            }*/
+            
+        /*if(i>=6){
+            f=f+1;
+            i=0;
+            }*/
+            //rpm=(6.2831*f)*(60/6.2831);
+            pc.printf("rpm=  %.2f",rpm);
+        //h=rea-50000;
+       // pc.printf("%s",);
+       // std::string Convert(float rea);
+        //cadena=float.toString("%f",rea);
+        //pc.printf("%s",cadena);
+        }
+      
+}
+
+void velocidad(int a,float ad){
+    switch (a){
+        case 0:
+            l1=0;
+            l2=0;
+            break;
+        case 1:
+            l1.write(ad);
+            l2=0;
+            break;
+        case 2:
+            l2.write(ad);
+            l1=0;
+            break;
+        
+  }  
+  
+  
+        
+}
+
diff -r 000000000000 -r b9f21a1a1fac mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 26 06:28:16 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file