Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:7ea6fb21e108
- Parent:
- 1:fccdc54f1314
--- a/main.cpp Fri Dec 04 12:31:29 2020 +0000
+++ b/main.cpp Sun Dec 13 21:29:23 2020 +0000
@@ -30,8 +30,9 @@
int recorrido=0,rpm1=0;
char cade;
bool bit=false;
-int velram;
+int velram=20;
float tiempoe=0;
+int angulo=0;
//using namespace boost;
float h;
void inicio(){
@@ -46,33 +47,35 @@
lcd.cls();
lcd.locate(0,1);
lcd.printf("millos");
- if(bit){
- velram=velram+1;
- if (velram >=20){
- velram=20;
- }
- } }
+ lcd.locate(0,1);
+ if(second>0){
+ velram=velram-1;
+ if( velram <= 1){
+ velram=1;
+ }
+ // if(bit){
+
+ }
+ }
+
int main(){
velocidad(0,0);
- inicio();
+ second=0;
velocidad(0,0);
+ selec=1;
+ rpm1=40;
lcd.printf("esta en los extremos");
int red=0;
- char buffer[12],aux[4];
+ char buffer[15],aux[4];
+ rampa.attach(&rampa1,0.5);
while(1){
- if(second==0){
- rampa.attach(&rampa1,1*0.05);
- }else{
- rampa.attach(&rampa1,second*0.05);
- }
-
if(pc.readable()){// captura string
- pc.gets(buffer,12);
+ pc.gets(buffer,15);
buffer[0]=' ';
- cade=buffer[1];
- if (rpm1==0){
+ // cade=buffer[1];
+
aux[1]=buffer[1];
aux[2]=buffer[2];
aux[3]=buffer[3];
@@ -85,31 +88,39 @@
aux[2]=buffer[8];
aux[3]=buffer[9];
distancia=dist(aux);
-
- }
+ aux[1]=buffer[10];
+ aux[2]=buffer[11];
+ aux[3]=buffer[12];
+ angulo=dist(aux);
+ if(distancia >0){
+ distancia=distancia*50;
}
-
- if(distancia>0){
- bit=true;
- velram=1;
- distancia=distancia*46;
+ if(second<1){
+ velram=second*2;
+ }
+ if(rpm1>45){
+
+ rpm1=40;}
}
-
- //pc.printf("%s",buffer);
- // dist(buffer);
- //pc.printf("%s",cadena);
- pc.printf("%d",recorrido);
+ if(distancia>0){
+ bit=true;
+ }
+
+
+ if((contador<distancia)&&(distancia>0)){
+ auxrpm=(float(60*velram))/(float(rpm1*256));
+ velocidad(selec,auxrpm);
+ }
+
+ if((contador==distancia)&&(distancia>0)){
+ distancia=0;
+ contador=0;
+ rpm1=0;
+ second=0;
+ // bit=false;
+ }
+
- if(( distancia>0)&&(contador<=distancia)){
- auxrpm=(60*20)/(rpm1*46*velram);
- velocidad(selec,auxrpm);
-
- }if(contador==distancia){
- contador=0;
- distancia=0;
- second=0;
-
- }
if(cade=='d'){
selec=1;
@@ -122,12 +133,12 @@
if(cade=='n'){selec=0;
}
- pc.printf("%d ,%d ,%d ",rpm1,distancia,second);
-
-
+
+ pc.printf(" v %d , %d ,%d ,%c , %.5f",velram,rpm1,distancia,cade,auxrpm);
+
}
-
+
}
void velocidad(int a ,float ad){
@@ -143,8 +154,10 @@
break;
case 1:
-
- for( int P=1;P<=4;P++){
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("izquierda");
+ for( int P=0;P<=3;P++){
contador=contador+1;
switch (P) {
case 0:
@@ -164,18 +177,20 @@
wait(ad);
}
- lcd.cls();
+ /* lcd.cls();
lcd.locate(0,0);
lcd.printf("%d mm",distancia);
lcd.locate(0,1);
lcd.printf(" V :%.2f rpm",rpm);
l1.write(ad);
- l2=0;
+ l2=0;*/
break;
case 2:
-
- for( int b=4;b>=1;b--){
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("derecha");
+ for( int b=3;b>=0;b--){
contador=contador+1;
switch (b) {
case 0:
@@ -195,14 +210,14 @@
wait(ad);
}
- lcd.cls();
+ /*lcd.cls();
lcd.locate(0,0);
lcd.printf("%d mm",distancia);
lcd.locate(0,1);
lcd.printf("%.2f rpm",rpm);
l2.write(ad);
- l1=0;
+ l1=0;*/
break;
}