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:
- 5:d165935ba818
- Parent:
- 4:7a06dce3de99
- Child:
- 6:35c069133c9a
--- a/main.cpp Fri Apr 19 18:09:38 2019 +0000
+++ b/main.cpp Tue Apr 23 04:10:50 2019 +0000
@@ -70,12 +70,12 @@
uint32_t VELOCITY = 400 ; // Tiempo en micro segundos
int16_t Lectura [ 2 ] = {} ;
- double In[ 1 ] = { } ;
+ double In [ 1 ] = {} ;
// definición de las funciones
- void setup_uart();
- void leer_datos();
- void leer_color();
+ void setup_uart ();
+ void leer_datos ();
+ void leer_color ();
void funcionesrobot ( uint8_t _Parametro, uint8_t _Comando );
int main() {
@@ -101,7 +101,7 @@
for ( i = 0 ; i < 2 ; i++){
Lectura [ i ] = command.getc();
- printf ( " %4d ", Lectura [ i ]);
+ //printf ( " %4d ", Lectura [ i ]);
}
}
@@ -270,54 +270,53 @@
case 1 :
printf ( "Frecuencia: 2000 Tiempo: %d s \n" , _Parametro ) ;
- mybuzzer.period_us( DO ) ;
- mybuzzer.write( 0.8 ) ;
+ mybuzzer.period_us ( DO ) ;
+ mybuzzer.write ( 0.8 ) ;
wait( _Parametro ) ;
- mybuzzer.write( 0 ) ;
+ mybuzzer.write ( 0 ) ;
break ;
case 2 :
printf ( "Frecuencia: 2500 Tiempo: %d s \n" , _Parametro ) ;
- mybuzzer.period_us( RE ) ;
- mybuzzer.write( 0.8 ) ;
- wait( _Parametro ) ;
- mybuzzer.write( 0 ) ;
+ mybuzzer.period_us ( RE ) ;
+ mybuzzer.write ( 0.8 ) ;
+ wait ( _Parametro ) ;
+ mybuzzer.write ( 0 ) ;
break ;
case 3 :
printf ( " Frecuencia: 3000 " ); printf ( " Tiempo: %d s \n " , _Parametro ) ;
- mybuzzer.period_us( MI ) ;
- mybuzzer.write( 0.8 ) ;
+ mybuzzer.period_us ( MI ) ;
+ mybuzzer.write ( 0.8 ) ;
wait( _Parametro ) ;
- mybuzzer.write( 0 ) ;
+ mybuzzer.write ( 0 ) ;
break ;
case 4:
printf ( "Frecuencia: 3500 Tiempo: %d s \n" , _Parametro ) ;
- mybuzzer.period_us( FA );
- mybuzzer.write( 0.8 );
- wait( 5 );
- mybuzzer.write(0);
+ mybuzzer.period_us ( FA );
+ mybuzzer.write ( 0.8 );
+ wait ( 5 );
+ mybuzzer.write ( 0 );
break ;
case 5 :
steppeer_dir = 1 ;
steppeer_dir2 = 0 ;
- wait_us( 1 );
+ wait_us ( 1 );
for ( j = 1 ; j <= _Parametro ; j++){
for ( i= 0 ; i <= 200 ; i++ ){
stepper_step = 1 ;
stepper_step2 = 1;
- wait_us(VELOCITY);
+ wait_us( VELOCITY );
stepper_step = 0;
stepper_step2 = 0;
- wait_us(VELOCITY);
+ wait_us ( VELOCITY );
}
-
}
break;
@@ -325,7 +324,7 @@
case 6 :
steppeer_dir = 0;
steppeer_dir2 = 1;
- wait_us( 1 );
+ wait_us ( 1 );
for ( j = 1 ; j <= _Parametro ; j++){
@@ -333,10 +332,10 @@
stepper_step = 1 ;
stepper_step2 = 1 ;
- wait_us(VELOCITY) ;
+ wait_us( VELOCITY ) ;
stepper_step = 0 ;
stepper_step2 = 0 ;
- wait_us(VELOCITY) ;
+ wait_us ( VELOCITY ) ;
}
@@ -345,8 +344,8 @@
break;
case 7:
- steppeer_dir = 1;
- wait_us( 1 );
+ steppeer_dir = 0;
+ wait_us ( 1 );
for ( j = 1 ; j <= _Parametro ; j++){
@@ -360,15 +359,14 @@
wait_us(VELOCITY) ;
}
-
}
break;
case 8 :
- steppeer_dir = 1;
- wait_us( 1 );
+ steppeer_dir2 = 1;
+ wait_us ( 1 );
for ( j = 1 ; j <= _Parametro ; j++){
@@ -376,10 +374,10 @@
//stepper_step = 1 ;
stepper_step2 = 1 ;
- wait_us(VELOCITY) ;
+ wait_us( VELOCITY ) ;
//stepper_step = 0 ;
stepper_step2 = 0 ;
- wait_us(VELOCITY) ;
+ wait_us ( VELOCITY ) ;
}
@@ -414,18 +412,22 @@
break;
case 10:
-
- switch ( _Parametro ){
+
+ int8_t Exit = 0 ;
+ if ( _Parametro == 1){
+
+ while ( !Exit ){
- case 1:
- In[0] = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
- printf(" X = %.04f \n", In[0]);
+ In [ 0 ] = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+ //printf(" X = %.04f \n", In[0]);
+ In [ 1 ] = analog_value1.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+ //printf(" X = %.04f \n", In[0]);
- while ( In[0] >= 0.9 ){
+ if ( In [ 0 ] > 0.5 ){
steppeer_dir = 1;
wait_us( 1 );
-
+
for ( i= 0 ; i <= 50 ; i++ ){
stepper_step = 1 ;
@@ -434,11 +436,10 @@
stepper_step = 0 ;
//stepper_step2 = 0 ;
wait_us( VELOCITY ) ;
- In[0] = analog_value0.read();
}
}
- while ( In[0] <= 0.4 ){
+ if ( In[ 0 ] < 0.5 ){
steppeer_dir2 = 1;
wait_us( 1 );
@@ -451,16 +452,16 @@
//stepper_step = 0 ;
stepper_step2 = 0 ;
wait_us( VELOCITY ) ;
- In[0] = analog_value0.read();
+
}
}
- In[1] = analog_value1.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
- printf(" Y = %.04f \n", In[1]);
- while (In[1] >= 0.9){
+
+ if (In [ 1 ] > 0.5 ){
steppeer_dir = 1 ;
steppeer_dir2 = 0 ;
wait_us( 1 );
+
for ( i= 0 ; i <= 50 ; i++ ){
stepper_step = 1 ;
@@ -471,15 +472,14 @@
wait_us( VELOCITY ) ;
}
- In[1] = analog_value1.read();
-
}
- while (In[1] <= 0.4){
+ if ( In [ 1 ] < 0.5 ){
steppeer_dir = 0 ;
steppeer_dir2 = 1 ;
wait_us( 1 );
+
for ( i= 0 ; i <= 50 ; i++ ){
stepper_step = 1 ;
@@ -487,42 +487,26 @@
wait_us( VELOCITY ) ;
stepper_step = 0 ;
stepper_step2 = 0 ;
- wait_us( VELOCITY ) ;
+ wait_us ( VELOCITY ) ;
}
- In[1] = analog_value1.read();
}
wait ( 1 );
-
- break;
-
- case 2:
+
+ if ( command.readable () == 1 ){
+
+ leer_datos();
+
+ if ( Lectura [ 1 ] == 02 ){
+
+ Exit = 1 ;
+ }
+ }
- In[0] = 0 ;
- In[1] = 0 ;
- printf(" X = %.04f, Y = %.04f \n", In[0], In[1] );
-
+ }
+ }
break;
-
}
- break;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
+ }
+