Piccolo
Dependencies: mbed
Fork of 02_LAB_serial_protocol by
Diff: main.cpp
- Revision:
- 18:acc0ff6b308d
- Parent:
- 17:53c6058d2021
--- a/main.cpp Tue Oct 24 00:06:48 2017 +0000 +++ b/main.cpp Sat Nov 11 14:45:29 2017 +0000 @@ -10,9 +10,10 @@ PwmOut myServoX(PB_3); //Servo X PwmOut myServoY(PB_4); //Servo Y PwmOut myServoZ(PC_7); //Servo Z -InterruptIn button(USER_BUTTON); // interrupcion boton stop -volatile bool button1_pressed = false; -volatile bool button1_enabled = true; +InterruptIn button1(USER_BUTTON); // interrupcion boton stop +volatile bool button1_pressed = false; // Used in the main loop +volatile bool button1_enabled = true; // Used for debouncing +Timeout button1_timeout; //***************************************************************************** // COMANDO MOVER MOTOR @@ -368,25 +369,24 @@ void Stop() //Funcion para detener el programa { exit(0); - - /* if(ST == 0){ - home(); - #if DEBUG - command.printf("\n...Parada total...\n", ST); - #endif - exit(ST); - } */ + } -void Pausa(int p) //Funcion para definir el tiempo de led +void Pausa(void) //Funcion para definir el tiempo de led { + button1_enabled = true; #if DEBUG command.printf("\n...Pausado...\n"); #endif } - -void Reanudar(int det) //Funcion para definir el tiempo de led + +void Reanudar(void) //Funcion para definir el tiempo de led { + if (button1_enabled) { // Disabled while the button is bouncing + button1_enabled = false; + button1_pressed = true; // To be read by the main loop + button1_timeout.attach(callback(Pausa), 0.3); // Debounce time 300 ms + } #if DEBUG command.printf("\nReanudando imagen...%i/n", DET); #endif @@ -475,14 +475,14 @@ #if DEBUG command.printf(" PAUSA\n"); #endif - Pausa(buffer_command[INITPARAMETER]); + // Pausa(buffer_command[INITPARAMETER]); break; case (REANUDAR_NC): #if DEBUG command.printf(" REANUDAR\n"); #endif - Reanudar(buffer_command[INITPARAMETER]); + // Reanudar(buffer_command[INITPARAMETER]); break; /* case (MOVER_NC): @@ -511,21 +511,35 @@ command.printf("inicio sin debug\n"); #endif uint8_t val; - button.fall(&Stop); + char estado = '0'; + button1.fall(&Stop); + button1.fall(callback(Reanudar)); + int idx = 0; while(1){ + + val=command.getc(); - - if (val== '<'){ + estado = command.getc(); + switch(estado){ + case '0': + if (val== '<'){ Read_command(); if (check_command()){ command_exe(); #if DEBUG echo_command(); #endif - if(button1_pressed ==false){ - } + } - } + } + break; + + case 'p': + button1_pressed = false; + printf("Button pressed %d\n", idx++); + break; + } + } }