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:
- 11:6b3570e525a1
- Parent:
- 10:92350e68d5ee
diff -r 92350e68d5ee -r 6b3570e525a1 main.cpp
--- a/main.cpp Tue Apr 23 15:35:23 2019 +0000
+++ b/main.cpp Fri May 17 03:56:46 2019 +0000
@@ -65,14 +65,58 @@
AnalogIn analog_value0 ( A0 ) ;
AnalogIn analog_value1 ( A1 ) ;
PwmOut mybuzzer( PB_9 ) ;
+ Ticker tk1;
+ volatile int Exit = 0 ;
+
+/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||/ /
+/ | |/
+/ | Interrupcion del Joystick- Eliminando ruido |/
+/ | |/
+/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
-/* ||Definicion de Puertos || */
+//Definicion de variables
+DigitalOut led1(LED1);
+InterruptIn Button_joy(USER_BUTTON);
+Timeout Button_joy_timeout; // Used for debouncing
+
+
+//Definicion de las funciones
+volatile bool Button_joy_pressed = false; // Used in the main loop
+volatile bool Button_joy_enabled = true; // Used for debouncing
+
+// Habilita el botón cuando termina el rebote.
+void Button_joy_enabled_cb(void)
+{
+ Button_joy_enabled = true;
+}
+
+// ISR Luego de precionar el boton
+void Button_joy_onpressed_cb(void)
+{
+ if (Button_joy_enabled) { // Desabilitado mientras e ruido
+ Button_joy_enabled = false;
+ Button_joy_pressed = true; // Se cambia el valor para ser leido más adelante
+ Button_joy_timeout.attach(callback(Button_joy_enabled_cb), 0.3); // Delay de 300 ms
+ }
+ if (Button_joy_pressed) { // Etablece cuando se preciona el botn
+ Button_joy_pressed = false;
+ //NVIC_SystemReset();
+ led1 = !led1;
+ }
+}
+/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||/ /
+/ |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||/
+/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
+
+void Rx_interrupt();
+
+/*Definicion de variables codigo principal*/
uint32_t VELOCITY = 400 ; // Tiempo en micro segundos
int16_t Lectura [ 2 ] = {} ;
double In [ 1 ] = {} ;
-// definición de las funciones
+// Definición de las funciones bucle principal
void setup_uart ();
void leer_datos ();
void leer_color ();
@@ -81,14 +125,20 @@
int main() {
setup_uart();
+ tk1.attach ( &leer_color, 0.8 ); // Se dirigue a la funcion leer_color cada 0.8 segundos
+ Button_joy.fall(callback(Button_joy_onpressed_cb)); // Llama a la funcion Button_joy_onpressed_cb al precionar el botón
+
while(1){
-
+
+ //Interrupcion boton
leer_datos();
funcionesrobot ( Lectura [ 1 ], Lectura [ 0 ] );
}
}
+//Declaracion de las funciones
+
void setup_uart(){
command.baud(115200);
@@ -108,7 +158,9 @@
}
}
-
+void Rx_interrupt() {
+ Exit = 1;
+}
void leer_color(){
mybuzzer.write(0);
@@ -139,11 +191,6 @@
if ( frqblue >= 5.0 and frqblue <= 29.0 ) {
- printf ( "tiende a rojo \n" );
- mybuzzer.period_us(DO);
- mybuzzer.write (0.8);
- wait (5);
- mybuzzer.write (0);
sel_color = 1;
}
@@ -158,11 +205,6 @@
if ( frqblue >= 10.0 and frqblue <= 26.0 ) {
- printf ( "tiende a verde \n" );
- mybuzzer.period_us(RE);
- mybuzzer.write (0.5);
- wait (5);
- mybuzzer.write (0);
sel_color = 2;
}
@@ -177,11 +219,6 @@
if ( frqred >= 5.0 and frqred <= 20.0 ) {
- printf ( "tiende a azul \n" );
- mybuzzer.period_us (MI);
- mybuzzer.write (1);
- wait (5);
- mybuzzer.write (0);
sel_color = 3;
}
@@ -195,12 +232,7 @@
if( frqgreen >= 20.0 and frqgreen <= 40.0) {
if ( frqred >= 20.0 and frqred <= 50.0 ) {
-
- printf ( "tiende a amarillo \n" );
- mybuzzer.period_us (FA);
- mybuzzer.write (0.6);
- wait (5);
- mybuzzer.write( 0);
+
sel_color = 4;
}
@@ -217,7 +249,8 @@
//int32_t enviar5 = RESPUESTA5 ;
//char txt5 [6] ;
//printf ( txt5 , "%02X" , enviar5 );
- printf ( " FF00 \n " );
+ command.putc( 0xFE );
+ command.putc( 0x00 );
break ;
@@ -225,7 +258,8 @@
//int32_t enviar1 = RESPUESTA1 ;
//char txt1 [6] ;
- printf ( "FE01 \n" );
+ command.putc( 0xFE );
+ command.putc( 0x01 );
sel_color = 0;
break ;
@@ -234,7 +268,8 @@
//int32_t enviar2 = RESPUESTA2 ;
//char txt2 [6] ;
- printf ( "FE02 \n" ) ;
+ command.putc ( 0xFE );
+ command.putc ( 0x02 );
sel_color = 0;
break ;
@@ -243,7 +278,8 @@
//int32_t enviar3 = RESPUESTA3;
//char txt3 [6] ;
- printf ( "FE03 \n" );
+ command.putc ( 0xFE );
+ command.putc ( 0x03 );
sel_color = 0;
break ;
@@ -252,7 +288,8 @@
//int32_t enviar4 = RESPUESTA4;
//char txt4 [6] ;
- printf ( "FE04 \n" );
+ command.putc ( 0xFE );
+ command.putc ( 0x04 );
sel_color = 0;
break ;
@@ -268,11 +305,11 @@
switch ( _Comando ){
// Acciones que ejerce el robot
- case 0 :
+ /*case 0 :
leer_color() ;
- break ;
+ break ; */
case 1 :
@@ -365,7 +402,7 @@
for ( j = 1 ; j <= _Parametro ; j++){
- for ( i= 0 ; i <= 50 ; i++ ){
+ for ( i= 0 ; i <= 250 ; i++ ){
stepper_step = 1 ;
//stepper_step2 = 1 ;
@@ -386,7 +423,7 @@
for ( j = 1 ; j <= _Parametro ; j++){
- for ( i= 0 ; i <= 50 ; i++ ){
+ for ( i= 0 ; i <= 250 ; i++ ){
//stepper_step = 1 ;
stepper_step2 = 1 ;
@@ -429,7 +466,7 @@
case 10:
- int8_t Exit = 0 ;
+
if ( _Parametro == 1){
while ( !Exit ){
@@ -509,7 +546,8 @@
}
- if ( command.readable () == 1 ){
+ command.attach( callback(Rx_interrupt), Serial::RxIrq );
+ /*if ( command.readable () == 1 ){
uint8_t l1, l2 ;
@@ -521,7 +559,7 @@
Exit = 1 ;
}
- }
+ }*/
wait_us ( 1 );