Proyecto final de semestre: Se desarrollo un vehículo que recibe comandos por el puerto serial y realiza las siguientes funciones según el comando sea el comando recibido: - Genera distintos tonos por un buzzer. - Controla el movimiento de un carro (con 2 motores) con comandos - Controla el movimiento de un carro (con 2 motores) con Joystick. - Lee y envía el color leido por el puerto serial al PC - Muestra los colores leídos por una pantalla FFT instalada en el vehículo.

Dependencies:   mbed UniGraphic

Committer:
CCastrop1012
Date:
Fri Sep 03 05:26:27 2021 +0000
Revision:
0:3a420fc22672
Proyecto de final de semestre, finalizado y funcional.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CCastrop1012 0:3a420fc22672 1 #include "mbed.h"
CCastrop1012 0:3a420fc22672 2 #include "Motor.h"
CCastrop1012 0:3a420fc22672 3 #include "scolor_TCS3200.h"
CCastrop1012 0:3a420fc22672 4
CCastrop1012 0:3a420fc22672 5 #include "Arial12x12.h"
CCastrop1012 0:3a420fc22672 6 #include "Arial24x23.h"
CCastrop1012 0:3a420fc22672 7 #include "Arial43x48_numb.h"
CCastrop1012 0:3a420fc22672 8 #include "pict.h"
CCastrop1012 0:3a420fc22672 9 #include "pavement_48x34.h"
CCastrop1012 0:3a420fc22672 10 #include "ILI9341.h"
CCastrop1012 0:3a420fc22672 11
CCastrop1012 0:3a420fc22672 12 // Puerto de comunicacion Serial
CCastrop1012 0:3a420fc22672 13 Serial CoolTerm(USBTX, USBRX);
CCastrop1012 0:3a420fc22672 14
CCastrop1012 0:3a420fc22672 15 // TFT
CCastrop1012 0:3a420fc22672 16 ILI9341* tft;
CCastrop1012 0:3a420fc22672 17
CCastrop1012 0:3a420fc22672 18 // Motores m1step
CCastrop1012 0:3a420fc22672 19 TraccionD Motores(PB_5, PB_3, PB_10, PB_4, 200, 3.75, 15.5) ;
CCastrop1012 0:3a420fc22672 20
CCastrop1012 0:3a420fc22672 21 /// PWM OUTPUTS
CCastrop1012 0:3a420fc22672 22 PwmOut Buzzer(D14); // LED1
CCastrop1012 0:3a420fc22672 23
CCastrop1012 0:3a420fc22672 24 // Temporizadores
CCastrop1012 0:3a420fc22672 25 Ticker MuestrearCOLOR;
CCastrop1012 0:3a420fc22672 26
CCastrop1012 0:3a420fc22672 27 // SENSOR DE COLOR
CCastrop1012 0:3a420fc22672 28 scolor_TCS3200 SENSOR_COLOR (PA_9, PC_7, PB_6, PA_7, PA_8);
CCastrop1012 0:3a420fc22672 29
CCastrop1012 0:3a420fc22672 30
CCastrop1012 0:3a420fc22672 31 // Lecturas Analogas de Joystick
CCastrop1012 0:3a420fc22672 32 AnalogIn JEjeX(A0);
CCastrop1012 0:3a420fc22672 33 AnalogIn JEjeY(A1);
CCastrop1012 0:3a420fc22672 34
CCastrop1012 0:3a420fc22672 35
CCastrop1012 0:3a420fc22672 36 // Salidas digitales
CCastrop1012 0:3a420fc22672 37 DigitalOut LED(PA_5);
CCastrop1012 0:3a420fc22672 38
CCastrop1012 0:3a420fc22672 39
CCastrop1012 0:3a420fc22672 40 // Interrupcion Externa
CCastrop1012 0:3a420fc22672 41 InterruptIn button1(USER_BUTTON);
CCastrop1012 0:3a420fc22672 42
CCastrop1012 0:3a420fc22672 43
CCastrop1012 0:3a420fc22672 44 //******************************************************************************
CCastrop1012 0:3a420fc22672 45 /// Declarar Variables Globales
CCastrop1012 0:3a420fc22672 46
CCastrop1012 0:3a420fc22672 47
CCastrop1012 0:3a420fc22672 48
CCastrop1012 0:3a420fc22672 49
CCastrop1012 0:3a420fc22672 50 /// Variables sensor de color
CCastrop1012 0:3a420fc22672 51 long red; //Almacenan el Tiempo que dura el CicloUtil de la frecuencia
CCastrop1012 0:3a420fc22672 52 long blue; //Generada por el Sensor TSC3200, al leer el componente
CCastrop1012 0:3a420fc22672 53 long green; //R, G, B o Clear del color que tenga en Frente
CCastrop1012 0:3a420fc22672 54 long clear;
CCastrop1012 0:3a420fc22672 55
CCastrop1012 0:3a420fc22672 56
CCastrop1012 0:3a420fc22672 57
CCastrop1012 0:3a420fc22672 58 /// Variables y Constantes para Interrupcion Serial
CCastrop1012 0:3a420fc22672 59 #define valorInicial 0xAA
CCastrop1012 0:3a420fc22672 60 uint8_t n_interrupcion = 0;
CCastrop1012 0:3a420fc22672 61 uint8_t ComandoRecivido = valorInicial;
CCastrop1012 0:3a420fc22672 62 uint8_t Parametro = valorInicial;
CCastrop1012 0:3a420fc22672 63
CCastrop1012 0:3a420fc22672 64
CCastrop1012 0:3a420fc22672 65 /// Constantes Sensor de Color
CCastrop1012 0:3a420fc22672 66 #define CMD_rojo 0x01
CCastrop1012 0:3a420fc22672 67 #define CMD_azul 0x02
CCastrop1012 0:3a420fc22672 68 #define CMD_verde 0x03
CCastrop1012 0:3a420fc22672 69 #define CMD_clear 0x04
CCastrop1012 0:3a420fc22672 70 #define ColorNoIdentificado 0x00
CCastrop1012 0:3a420fc22672 71
CCastrop1012 0:3a420fc22672 72
CCastrop1012 0:3a420fc22672 73 uint8_t color_identificado = ColorNoIdentificado;
CCastrop1012 0:3a420fc22672 74 uint8_t color_anterior = 0;
CCastrop1012 0:3a420fc22672 75
CCastrop1012 0:3a420fc22672 76
CCastrop1012 0:3a420fc22672 77 /// Varialbles Buzzer
CCastrop1012 0:3a420fc22672 78 uint8_t duracion_tono = 1; // Variable que almacena el Tiempo que es ESCUCHARÁ el Tono
CCastrop1012 0:3a420fc22672 79 uint8_t tipo_tono = 1; // Variable que almacena el Tono que se desee escuchar
CCastrop1012 0:3a420fc22672 80
CCastrop1012 0:3a420fc22672 81 /// Constantes Buzzer
CCastrop1012 0:3a420fc22672 82 #define TONO_DO 0x01 /// si tipo_tono == 0x01, se escuchará un DO
CCastrop1012 0:3a420fc22672 83 #define TONO_RE 0x02 /// si tipo_tono == 0x02, se escuchará un RE
CCastrop1012 0:3a420fc22672 84 #define TONO_MI 0x03 /// si tipo_tono == 0x03, se escuchará un MI
CCastrop1012 0:3a420fc22672 85 #define TONO_SI 0x04 /// si tipo_tono == 0x04, se escuchará un SI
CCastrop1012 0:3a420fc22672 86
CCastrop1012 0:3a420fc22672 87 #define DO 3.78 /// Duración del periodo en ms, que se pondrá en el Buzzer.period_ms() PARA ESCUCHAR UN DO
CCastrop1012 0:3a420fc22672 88 #define RE 3.36 /// Duración del periodo en ms, que se pondrá en el Buzzer.period_ms() PARA ESCUCHAR UN RE
CCastrop1012 0:3a420fc22672 89 #define MI 3.03 /// Duración del periodo en ms, que se pondrá en el Buzzer.period_ms() PARA ESCUCHAR UN MI
CCastrop1012 0:3a420fc22672 90 #define SI 2.82 /// Duración del periodo en ms, que se pondrá en el Buzzer.period_ms() PARA ESCUCHAR UN SI
CCastrop1012 0:3a420fc22672 91
CCastrop1012 0:3a420fc22672 92 Timeout TimeBuzzer;
CCastrop1012 0:3a420fc22672 93
CCastrop1012 0:3a420fc22672 94
CCastrop1012 0:3a420fc22672 95 #define limite 0.727
CCastrop1012 0:3a420fc22672 96
CCastrop1012 0:3a420fc22672 97 // variables de control y flujo de programa
CCastrop1012 0:3a420fc22672 98
CCastrop1012 0:3a420fc22672 99 uint8_t programa_ejecutar = 0; // Variable que almacena la ORDEN (Telemetria ó Telecomando)
CCastrop1012 0:3a420fc22672 100 // enviada desde el CoolTerm
CCastrop1012 0:3a420fc22672 101 uint8_t coolterm_data; // Se almacenan Todos los Caracteres recividos por el CoolTerm.
CCastrop1012 0:3a420fc22672 102
CCastrop1012 0:3a420fc22672 103 uint8_t new_command = 0;
CCastrop1012 0:3a420fc22672 104 // Constantes de velocidad
CCastrop1012 0:3a420fc22672 105
CCastrop1012 0:3a420fc22672 106 #define VelAlta 300
CCastrop1012 0:3a420fc22672 107 #define VelMedia 200
CCastrop1012 0:3a420fc22672 108 #define VelBaja 100
CCastrop1012 0:3a420fc22672 109
CCastrop1012 0:3a420fc22672 110
CCastrop1012 0:3a420fc22672 111 //******************************************************************************
CCastrop1012 0:3a420fc22672 112 // COMANDOS
CCastrop1012 0:3a420fc22672 113
CCastrop1012 0:3a420fc22672 114 #define iniciar_telemetria 0xFE
CCastrop1012 0:3a420fc22672 115 #define iniciar_telecomando 0xFF
CCastrop1012 0:3a420fc22672 116
CCastrop1012 0:3a420fc22672 117 #define telemetria_1 0x01 //
CCastrop1012 0:3a420fc22672 118 #define telemcomando_1 0x01
CCastrop1012 0:3a420fc22672 119
CCastrop1012 0:3a420fc22672 120 #define C_LeerColor 0x00
CCastrop1012 0:3a420fc22672 121 #define C_Sonido1 0x01
CCastrop1012 0:3a420fc22672 122 #define C_Sonido2 0x02
CCastrop1012 0:3a420fc22672 123 #define C_Sonido3 0x03
CCastrop1012 0:3a420fc22672 124 #define C_Sonido4 0x04
CCastrop1012 0:3a420fc22672 125 #define C_Adelante 0x05
CCastrop1012 0:3a420fc22672 126 #define C_Atras 0x06
CCastrop1012 0:3a420fc22672 127 #define C_Izquierda 0x07
CCastrop1012 0:3a420fc22672 128 #define C_Derecha 0x08
CCastrop1012 0:3a420fc22672 129 #define C_Velocidad 0x09
CCastrop1012 0:3a420fc22672 130 #define C_Joistck 0x0A
CCastrop1012 0:3a420fc22672 131
CCastrop1012 0:3a420fc22672 132 int comando_joystick = 0;
CCastrop1012 0:3a420fc22672 133
CCastrop1012 0:3a420fc22672 134
CCastrop1012 0:3a420fc22672 135 // variables y constantes del Joystick
CCastrop1012 0:3a420fc22672 136
CCastrop1012 0:3a420fc22672 137 uint8_t estado_x;
CCastrop1012 0:3a420fc22672 138 uint8_t estado_y;
CCastrop1012 0:3a420fc22672 139 #define E_Derecha 1
CCastrop1012 0:3a420fc22672 140 #define E_Izquier 0
CCastrop1012 0:3a420fc22672 141 #define E_Adelante 1
CCastrop1012 0:3a420fc22672 142 #define E_Atras 0
CCastrop1012 0:3a420fc22672 143 #define E_Centro 3
CCastrop1012 0:3a420fc22672 144 #define Lim_JKIn 150
CCastrop1012 0:3a420fc22672 145 #define Lim_JKSup 180
CCastrop1012 0:3a420fc22672 146
CCastrop1012 0:3a420fc22672 147
CCastrop1012 0:3a420fc22672 148
CCastrop1012 0:3a420fc22672 149 // Variables y constantes pulsador
CCastrop1012 0:3a420fc22672 150 volatile bool button1_pressed = false; // Used in the main loop
CCastrop1012 0:3a420fc22672 151 volatile bool button1_enabled = true; // Used for debouncing
CCastrop1012 0:3a420fc22672 152 Timeout button1_timeout; // Used for debouncing
CCastrop1012 0:3a420fc22672 153
CCastrop1012 0:3a420fc22672 154
CCastrop1012 0:3a420fc22672 155
CCastrop1012 0:3a420fc22672 156 bool ComandPend = true;
CCastrop1012 0:3a420fc22672 157
CCastrop1012 0:3a420fc22672 158 //****************************************************************************
CCastrop1012 0:3a420fc22672 159 // Prototipo de funciones
CCastrop1012 0:3a420fc22672 160 void Configuracion_Inicial(void);
CCastrop1012 0:3a420fc22672 161 void ReadPort(void); // Lee el puerto Serial
CCastrop1012 0:3a420fc22672 162 void MainConfig(void); // Configuracion Inicial de los Perifericos del uC
CCastrop1012 0:3a420fc22672 163 void Buzzer_Tone(uint8_t tipo_tono, uint8_t duracion_tono); // configura el tono y la duracion escuchada a travez del Buzzer
CCastrop1012 0:3a420fc22672 164 void leer_color(void); // funcion que retorna los componentes
CCastrop1012 0:3a420fc22672 165 // RGB y Clear del color leido
CCastrop1012 0:3a420fc22672 166 void leer_Joystick(void); // Ejerce control sobre el Movimiento del carro desde el Joistick
CCastrop1012 0:3a420fc22672 167 void intTimeBuzzer(void);
CCastrop1012 0:3a420fc22672 168
CCastrop1012 0:3a420fc22672 169 void button1_enabled_cb(void);
CCastrop1012 0:3a420fc22672 170 void button1_onpressed_cb(void);
CCastrop1012 0:3a420fc22672 171
CCastrop1012 0:3a420fc22672 172
CCastrop1012 0:3a420fc22672 173 //****************************************************************************
CCastrop1012 0:3a420fc22672 174 //
CCastrop1012 0:3a420fc22672 175
CCastrop1012 0:3a420fc22672 176 /// Variables y constantes para la TFT
CCastrop1012 0:3a420fc22672 177
CCastrop1012 0:3a420fc22672 178 const unsigned short FOREGROUND_COLORS[] = {White, Cyan, Red, Magenta, Yellow, Orange, GreenYellow};
CCastrop1012 0:3a420fc22672 179 const unsigned short BACKGROUND_COLORS[] = {Black, Green, Yellow, Blue, Magenta, Black, Red};
CCastrop1012 0:3a420fc22672 180 unsigned short backgroundColor;
CCastrop1012 0:3a420fc22672 181 unsigned short foregroundColor;
CCastrop1012 0:3a420fc22672 182 unsigned short colorIndex = 0;
CCastrop1012 0:3a420fc22672 183 char orient = 1;
CCastrop1012 0:3a420fc22672 184
CCastrop1012 0:3a420fc22672 185
CCastrop1012 0:3a420fc22672 186 void Configuracion_Inicial()
CCastrop1012 0:3a420fc22672 187 {
CCastrop1012 0:3a420fc22672 188
CCastrop1012 0:3a420fc22672 189 Buzzer.write(0); // configura el ciclo util
CCastrop1012 0:3a420fc22672 190 Motores.StepFreq(VelMedia); // Valor inicial de velocidad = Media
CCastrop1012 0:3a420fc22672 191 CoolTerm.attach(&ReadPort, Serial::RxIrq); // Se Habilita la interrupcion serial o recepcion de datos
CCastrop1012 0:3a420fc22672 192 //MuestrearCOLOR.attach(&leer_color, 0.6); // Se Habilita una interrupcion cada 0.6 Segundos para leer el color
CCastrop1012 0:3a420fc22672 193 tft = new ILI9341(SPI_8, 10000000, PC_12, PC_11, PC_10, PA_13, PA_14, PA_15, "tft"); // SPI type, SPI speed, mosi, miso, sclk, cs, reset, dc
CCastrop1012 0:3a420fc22672 194 tft->set_orientation(orient); // horizontal 1
CCastrop1012 0:3a420fc22672 195
CCastrop1012 0:3a420fc22672 196 CoolTerm.baud(115200);
CCastrop1012 0:3a420fc22672 197 //CoolTerm.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000);
CCastrop1012 0:3a420fc22672 198 //tft->printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000);
CCastrop1012 0:3a420fc22672 199 foregroundColor = FOREGROUND_COLORS[0]; // white
CCastrop1012 0:3a420fc22672 200 backgroundColor = BACKGROUND_COLORS[0];// DarkCyan
CCastrop1012 0:3a420fc22672 201
CCastrop1012 0:3a420fc22672 202 tft->background(backgroundColor); // set background to black
CCastrop1012 0:3a420fc22672 203 tft->set_orientation(orient);
CCastrop1012 0:3a420fc22672 204 tft->cls(); // clear the screen
CCastrop1012 0:3a420fc22672 205
CCastrop1012 0:3a420fc22672 206
CCastrop1012 0:3a420fc22672 207
CCastrop1012 0:3a420fc22672 208
CCastrop1012 0:3a420fc22672 209
CCastrop1012 0:3a420fc22672 210 tft->set_font((unsigned char*) Arial24x23,32,127,false); //variable width disabled
CCastrop1012 0:3a420fc22672 211 tft->locate(80,80);
CCastrop1012 0:3a420fc22672 212 tft->printf("COLOR \n\t\t NO \n\tIDENTIFICADO \r\n");
CCastrop1012 0:3a420fc22672 213
CCastrop1012 0:3a420fc22672 214
CCastrop1012 0:3a420fc22672 215 //button1.mode(PullUp); // Activate pull-up
CCastrop1012 0:3a420fc22672 216 button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event
CCastrop1012 0:3a420fc22672 217
CCastrop1012 0:3a420fc22672 218
CCastrop1012 0:3a420fc22672 219 }
CCastrop1012 0:3a420fc22672 220
CCastrop1012 0:3a420fc22672 221
CCastrop1012 0:3a420fc22672 222
CCastrop1012 0:3a420fc22672 223
CCastrop1012 0:3a420fc22672 224
CCastrop1012 0:3a420fc22672 225
CCastrop1012 0:3a420fc22672 226 // Enables button when bouncing is over
CCastrop1012 0:3a420fc22672 227 void button1_enabled_cb(void)
CCastrop1012 0:3a420fc22672 228 {
CCastrop1012 0:3a420fc22672 229 button1_enabled = true;
CCastrop1012 0:3a420fc22672 230 if (button1_enabled)
CCastrop1012 0:3a420fc22672 231 {
CCastrop1012 0:3a420fc22672 232 // Reinicializamos nuestras variables de control a sus valores iniciales
CCastrop1012 0:3a420fc22672 233 // Para no seguir entrando a las sentencias IF
CCastrop1012 0:3a420fc22672 234 programa_ejecutar = 0;
CCastrop1012 0:3a420fc22672 235 coolterm_data = 0;
CCastrop1012 0:3a420fc22672 236 ComandoRecivido = valorInicial;
CCastrop1012 0:3a420fc22672 237 Parametro = valorInicial;
CCastrop1012 0:3a420fc22672 238 Motores.Stop();
CCastrop1012 0:3a420fc22672 239 TimeBuzzer.attach(&intTimeBuzzer, 0);
CCastrop1012 0:3a420fc22672 240 ComandPend = false;
CCastrop1012 0:3a420fc22672 241 }
CCastrop1012 0:3a420fc22672 242 }
CCastrop1012 0:3a420fc22672 243
CCastrop1012 0:3a420fc22672 244 // ISR handling button pressed event
CCastrop1012 0:3a420fc22672 245 void button1_onpressed_cb(void)
CCastrop1012 0:3a420fc22672 246 {
CCastrop1012 0:3a420fc22672 247 if (button1_enabled)
CCastrop1012 0:3a420fc22672 248 { // Disabled while the button is bouncing
CCastrop1012 0:3a420fc22672 249 button1_enabled = false;
CCastrop1012 0:3a420fc22672 250 button1_pressed = true; // To be read by the main loop
CCastrop1012 0:3a420fc22672 251 button1_timeout.attach(callback(button1_enabled_cb), 0.3); // Debounce time 300 ms
CCastrop1012 0:3a420fc22672 252 }
CCastrop1012 0:3a420fc22672 253
CCastrop1012 0:3a420fc22672 254
CCastrop1012 0:3a420fc22672 255
CCastrop1012 0:3a420fc22672 256 }
CCastrop1012 0:3a420fc22672 257
CCastrop1012 0:3a420fc22672 258
CCastrop1012 0:3a420fc22672 259
CCastrop1012 0:3a420fc22672 260
CCastrop1012 0:3a420fc22672 261 void ReadPort()
CCastrop1012 0:3a420fc22672 262 {
CCastrop1012 0:3a420fc22672 263 uint8_t temp = CoolTerm.getc();
CCastrop1012 0:3a420fc22672 264 //if(CoolTerm.writable()) CoolTerm.abort_write(); // ELIMINA LO QUE ESTEMOS ESCRIBIENDO AL COOLTERM
CCastrop1012 0:3a420fc22672 265 if (ComandPend == true)
CCastrop1012 0:3a420fc22672 266 {
CCastrop1012 0:3a420fc22672 267 switch(n_interrupcion)
CCastrop1012 0:3a420fc22672 268 {
CCastrop1012 0:3a420fc22672 269 case 00: coolterm_data = temp;
CCastrop1012 0:3a420fc22672 270 if (coolterm_data == iniciar_telecomando)
CCastrop1012 0:3a420fc22672 271 n_interrupcion = 1;
CCastrop1012 0:3a420fc22672 272 break;
CCastrop1012 0:3a420fc22672 273 case 01: ComandoRecivido = temp;
CCastrop1012 0:3a420fc22672 274 n_interrupcion=2;
CCastrop1012 0:3a420fc22672 275 break;
CCastrop1012 0:3a420fc22672 276 case 02: Parametro = temp;
CCastrop1012 0:3a420fc22672 277 n_interrupcion = 0;
CCastrop1012 0:3a420fc22672 278 ComandPend=false;
CCastrop1012 0:3a420fc22672 279 break;
CCastrop1012 0:3a420fc22672 280
CCastrop1012 0:3a420fc22672 281 }
CCastrop1012 0:3a420fc22672 282
CCastrop1012 0:3a420fc22672 283 }
CCastrop1012 0:3a420fc22672 284
CCastrop1012 0:3a420fc22672 285
CCastrop1012 0:3a420fc22672 286 }
CCastrop1012 0:3a420fc22672 287
CCastrop1012 0:3a420fc22672 288 ///******************************************+
CCastrop1012 0:3a420fc22672 289
CCastrop1012 0:3a420fc22672 290
CCastrop1012 0:3a420fc22672 291 void leer_Joystick()
CCastrop1012 0:3a420fc22672 292 {
CCastrop1012 0:3a420fc22672 293
CCastrop1012 0:3a420fc22672 294 /// Variables Joystick
CCastrop1012 0:3a420fc22672 295 float EjeX;
CCastrop1012 0:3a420fc22672 296 float EjeY;
CCastrop1012 0:3a420fc22672 297 float Vx;
CCastrop1012 0:3a420fc22672 298 float Vy;
CCastrop1012 0:3a420fc22672 299
CCastrop1012 0:3a420fc22672 300 while ( ComandPend == true )
CCastrop1012 0:3a420fc22672 301 {
CCastrop1012 0:3a420fc22672 302
CCastrop1012 0:3a420fc22672 303 EjeX = JEjeX.read();
CCastrop1012 0:3a420fc22672 304 Vx = EjeX * 3300;
CCastrop1012 0:3a420fc22672 305 wait (0.1);
CCastrop1012 0:3a420fc22672 306 EjeY = JEjeY.read();
CCastrop1012 0:3a420fc22672 307 Vy = EjeY * 3300;
CCastrop1012 0:3a420fc22672 308
CCastrop1012 0:3a420fc22672 309 // CoolTerm.printf ("ejex: %f ejey: %f Vx: %f Vy: %f \n ", EjeX, EjeY, Vx, Vy);
CCastrop1012 0:3a420fc22672 310
CCastrop1012 0:3a420fc22672 311 if(int(Vx/10) > Lim_JKIn && int(Vx/10) < Lim_JKSup) {estado_x = E_Centro; }//(CoolTerm.printf ("Estado X Centro \n"); }
CCastrop1012 0:3a420fc22672 312 if(int(Vy/10) > Lim_JKIn && int(Vy/10) < Lim_JKSup) {estado_y = E_Centro; }//CoolTerm.printf ("Estado Y Centro \n"); }
CCastrop1012 0:3a420fc22672 313
CCastrop1012 0:3a420fc22672 314 if(int(Vx/10) > Lim_JKSup && estado_y == E_Centro){ estado_x = E_Izquier; }// CoolTerm.printf ("Estado X Izquierda\n"); }
CCastrop1012 0:3a420fc22672 315 if(int(Vy/10) > Lim_JKSup && estado_x == E_Centro){ estado_y = E_Atras; }// CoolTerm.printf ("Estado Y Adelante\n"); }
CCastrop1012 0:3a420fc22672 316
CCastrop1012 0:3a420fc22672 317 if(int(Vx/10) < Lim_JKIn && estado_y == E_Centro){ estado_x = E_Derecha; } //CoolTerm.printf ("Estado X Derecha\n"); }
CCastrop1012 0:3a420fc22672 318 if(int(Vy/10) < Lim_JKIn && estado_x == E_Centro){ estado_y = E_Adelante; } //CoolTerm.printf ("Estado Y Atras\n"); }
CCastrop1012 0:3a420fc22672 319
CCastrop1012 0:3a420fc22672 320
CCastrop1012 0:3a420fc22672 321 // Combinacion de estados para STOP
CCastrop1012 0:3a420fc22672 322 if( estado_x == E_Centro && estado_y == E_Centro){ Motores.Stop(); }//CoolTerm.printf ("MOTORES STOP\n"); }
CCastrop1012 0:3a420fc22672 323
CCastrop1012 0:3a420fc22672 324 // Combinacion de estados para ADELANTE
CCastrop1012 0:3a420fc22672 325 if(estado_x == E_Centro && estado_y == E_Adelante) { Motores.Back(); Motores.Run(0.5); }// CoolTerm.printf ("MOTORES BACK\n"); }
CCastrop1012 0:3a420fc22672 326
CCastrop1012 0:3a420fc22672 327 // Combinacion de estados para ATRAS
CCastrop1012 0:3a420fc22672 328 if(estado_x == E_Centro && estado_y == E_Atras) { Motores.Forward(); Motores.Run(0.5); }// CoolTerm.printf ("MOTORES FORWARD\n"); }
CCastrop1012 0:3a420fc22672 329
CCastrop1012 0:3a420fc22672 330
CCastrop1012 0:3a420fc22672 331 // Combinacion de estados para DERECHA
CCastrop1012 0:3a420fc22672 332 if(estado_y == E_Centro && estado_x == E_Derecha) { Motores.Giro(15, false); Motores.Run(0.5); } // CoolTerm.printf ("MOTORES DERECHA\n"); }
CCastrop1012 0:3a420fc22672 333
CCastrop1012 0:3a420fc22672 334 // Combinacion de estados para IZQUIERDA
CCastrop1012 0:3a420fc22672 335 if(estado_y == E_Centro && estado_x == E_Izquier) { Motores.Giro(15, true); Motores.Run(0.5); } // CoolTerm.printf ("MOTORES IZQUIERDA\n"); }
CCastrop1012 0:3a420fc22672 336 //wait(1.5);
CCastrop1012 0:3a420fc22672 337
CCastrop1012 0:3a420fc22672 338 if (ComandoRecivido == C_Joistck && Parametro == 0x02) break;
CCastrop1012 0:3a420fc22672 339 }
CCastrop1012 0:3a420fc22672 340
CCastrop1012 0:3a420fc22672 341
CCastrop1012 0:3a420fc22672 342 }
CCastrop1012 0:3a420fc22672 343
CCastrop1012 0:3a420fc22672 344
CCastrop1012 0:3a420fc22672 345
CCastrop1012 0:3a420fc22672 346 int main()
CCastrop1012 0:3a420fc22672 347 {
CCastrop1012 0:3a420fc22672 348
CCastrop1012 0:3a420fc22672 349 Configuracion_Inicial();
CCastrop1012 0:3a420fc22672 350
CCastrop1012 0:3a420fc22672 351 MuestrearCOLOR.attach(&leer_color, 1.5); // Se Habilita una interrupcion cada 0.6 Segundos para leer el color
CCastrop1012 0:3a420fc22672 352
CCastrop1012 0:3a420fc22672 353 while(1)
CCastrop1012 0:3a420fc22672 354 {
CCastrop1012 0:3a420fc22672 355
CCastrop1012 0:3a420fc22672 356 /// Espera hasta que no se tengan comandos pendientes
CCastrop1012 0:3a420fc22672 357 while(ComandPend == true)wait_ms(1);
CCastrop1012 0:3a420fc22672 358 ComandPend = true;
CCastrop1012 0:3a420fc22672 359
CCastrop1012 0:3a420fc22672 360
CCastrop1012 0:3a420fc22672 361 // Desactivamos la interrupcion serial o recepcion de datos PORQUE NO NECESITAMOS recibir mas datos por AHORA
CCastrop1012 0:3a420fc22672 362 // CoolTerm.attach(NULL, Serial::RxIrq);
CCastrop1012 0:3a420fc22672 363
CCastrop1012 0:3a420fc22672 364 switch(ComandoRecivido)
CCastrop1012 0:3a420fc22672 365 {
CCastrop1012 0:3a420fc22672 366
CCastrop1012 0:3a420fc22672 367 //case C_LeerColor: // Ejecutamos la Funcion LeerColor();
CCastrop1012 0:3a420fc22672 368 // leer_color();
CCastrop1012 0:3a420fc22672 369 //break;
CCastrop1012 0:3a420fc22672 370 case C_Sonido1: //CoolTerm.printf("SONIDO 1\n");
CCastrop1012 0:3a420fc22672 371 duracion_tono = Parametro; // lo almacenamos en: duracion_tono
CCastrop1012 0:3a420fc22672 372 tipo_tono = TONO_DO;
CCastrop1012 0:3a420fc22672 373 Buzzer_Tone(tipo_tono, duracion_tono);
CCastrop1012 0:3a420fc22672 374 break;
CCastrop1012 0:3a420fc22672 375 case C_Sonido2: //CoolTerm.printf("SONIDO 2\n");
CCastrop1012 0:3a420fc22672 376 duracion_tono = Parametro; // lo almacenamos en: duracion_tono
CCastrop1012 0:3a420fc22672 377 tipo_tono = TONO_RE;
CCastrop1012 0:3a420fc22672 378 Buzzer_Tone(tipo_tono, duracion_tono);
CCastrop1012 0:3a420fc22672 379 break;
CCastrop1012 0:3a420fc22672 380 case C_Sonido3: //CoolTerm.printf("SONIDO 3\n");
CCastrop1012 0:3a420fc22672 381 duracion_tono = Parametro; // lo almacenamos en: duracion_tono
CCastrop1012 0:3a420fc22672 382 tipo_tono = TONO_MI;
CCastrop1012 0:3a420fc22672 383 Buzzer_Tone(tipo_tono, duracion_tono);
CCastrop1012 0:3a420fc22672 384 break;
CCastrop1012 0:3a420fc22672 385 case C_Sonido4: //CoolTerm.printf("SONIDO 4\n");
CCastrop1012 0:3a420fc22672 386 duracion_tono = Parametro; // lo almacenamos en: duracion_tono
CCastrop1012 0:3a420fc22672 387 tipo_tono = TONO_SI;
CCastrop1012 0:3a420fc22672 388 Buzzer_Tone(tipo_tono, duracion_tono);
CCastrop1012 0:3a420fc22672 389 break;
CCastrop1012 0:3a420fc22672 390 case C_Adelante: Motores.Forward(); Motores.RunRound(Parametro);
CCastrop1012 0:3a420fc22672 391 break;
CCastrop1012 0:3a420fc22672 392 case C_Atras: Motores.Back(); Motores.RunRound(Parametro);
CCastrop1012 0:3a420fc22672 393 break;
CCastrop1012 0:3a420fc22672 394 case C_Izquierda: Motores.Giro(65, true);
CCastrop1012 0:3a420fc22672 395 break;
CCastrop1012 0:3a420fc22672 396 case C_Derecha: Motores.Giro(65, false);
CCastrop1012 0:3a420fc22672 397 break;
CCastrop1012 0:3a420fc22672 398 case C_Velocidad: if(Parametro == 0x01)Motores.StepFreq(VelBaja);
CCastrop1012 0:3a420fc22672 399 if(Parametro == 0x02)Motores.StepFreq(VelMedia);
CCastrop1012 0:3a420fc22672 400 if(Parametro == 0x03)Motores.StepFreq(VelAlta);
CCastrop1012 0:3a420fc22672 401 break;
CCastrop1012 0:3a420fc22672 402 case C_Joistck: leer_Joystick();
CCastrop1012 0:3a420fc22672 403 break;
CCastrop1012 0:3a420fc22672 404 default: break;
CCastrop1012 0:3a420fc22672 405
CCastrop1012 0:3a420fc22672 406
CCastrop1012 0:3a420fc22672 407 }
CCastrop1012 0:3a420fc22672 408
CCastrop1012 0:3a420fc22672 409
CCastrop1012 0:3a420fc22672 410 // Reinicializamos nuestras variables de control a sus valores iniciales
CCastrop1012 0:3a420fc22672 411 // Para no seguir entrando a las sentencias IF
CCastrop1012 0:3a420fc22672 412 if(ComandPend == true)
CCastrop1012 0:3a420fc22672 413 {
CCastrop1012 0:3a420fc22672 414 programa_ejecutar = 0;
CCastrop1012 0:3a420fc22672 415 coolterm_data = 0;
CCastrop1012 0:3a420fc22672 416 ComandoRecivido = valorInicial; Parametro = valorInicial;
CCastrop1012 0:3a420fc22672 417
CCastrop1012 0:3a420fc22672 418 }
CCastrop1012 0:3a420fc22672 419
CCastrop1012 0:3a420fc22672 420 //// HABILITAMOS NUEVAMENTE la interrupcion serial o recepcion de datos
CCastrop1012 0:3a420fc22672 421 // CoolTerm.attach(&ReadPort, Serial::RxIrq);
CCastrop1012 0:3a420fc22672 422
CCastrop1012 0:3a420fc22672 423 }
CCastrop1012 0:3a420fc22672 424
CCastrop1012 0:3a420fc22672 425 }
CCastrop1012 0:3a420fc22672 426
CCastrop1012 0:3a420fc22672 427
CCastrop1012 0:3a420fc22672 428
CCastrop1012 0:3a420fc22672 429 void Buzzer_Tone(uint8_t tipo_tono, uint8_t duracion_tono)
CCastrop1012 0:3a420fc22672 430 {
CCastrop1012 0:3a420fc22672 431
CCastrop1012 0:3a420fc22672 432
CCastrop1012 0:3a420fc22672 433 switch (tipo_tono)
CCastrop1012 0:3a420fc22672 434 {
CCastrop1012 0:3a420fc22672 435
CCastrop1012 0:3a420fc22672 436 case TONO_DO: Buzzer.period_ms(DO);
CCastrop1012 0:3a420fc22672 437 //CoolTerm.printf("Tono Seleccionado DO!!\n");
CCastrop1012 0:3a420fc22672 438
CCastrop1012 0:3a420fc22672 439 break; // salimos del SWITCH
CCastrop1012 0:3a420fc22672 440
CCastrop1012 0:3a420fc22672 441 case TONO_RE: Buzzer.period_ms(RE);
CCastrop1012 0:3a420fc22672 442 //CoolTerm.printf("Tono Seleccionado RE!!\n");
CCastrop1012 0:3a420fc22672 443
CCastrop1012 0:3a420fc22672 444 break; // salimos del SWITCH
CCastrop1012 0:3a420fc22672 445
CCastrop1012 0:3a420fc22672 446 case TONO_MI: Buzzer.period_ms(MI);
CCastrop1012 0:3a420fc22672 447 //CoolTerm.printf("Tono Seleccionado MI!!\n");
CCastrop1012 0:3a420fc22672 448
CCastrop1012 0:3a420fc22672 449 break; // salimos del SWITCH
CCastrop1012 0:3a420fc22672 450
CCastrop1012 0:3a420fc22672 451 case TONO_SI: Buzzer.period_ms(SI);
CCastrop1012 0:3a420fc22672 452 //CoolTerm.printf("Tono Seleccionado SI!!\n");
CCastrop1012 0:3a420fc22672 453
CCastrop1012 0:3a420fc22672 454 break; // salimos del SWITCH
CCastrop1012 0:3a420fc22672 455
CCastrop1012 0:3a420fc22672 456 // si no fue ninguno de los valores anteriores entonces:
CCastrop1012 0:3a420fc22672 457 default: //CoolTerm.printf("teleComando desconocido, inicie nuevamente !!\n");
CCastrop1012 0:3a420fc22672 458
CCastrop1012 0:3a420fc22672 459 break; // salimos del SWITCH
CCastrop1012 0:3a420fc22672 460
CCastrop1012 0:3a420fc22672 461 }
CCastrop1012 0:3a420fc22672 462
CCastrop1012 0:3a420fc22672 463 // COMO EL CICLO UTIL DEL BUZZER ESTABA EN 0, POR LO CUAL NO SONABA
CCastrop1012 0:3a420fc22672 464 // SE PONE AL 50% DEL PERIODO
CCastrop1012 0:3a420fc22672 465 Buzzer.write(0.5);
CCastrop1012 0:3a420fc22672 466 // SE ESPERA DURANTE EN TIEMPO INGRESADO (EN SEGUNDOS )
CCastrop1012 0:3a420fc22672 467 // wait(duracion_tono);
CCastrop1012 0:3a420fc22672 468
CCastrop1012 0:3a420fc22672 469 TimeBuzzer.attach(&intTimeBuzzer, duracion_tono);
CCastrop1012 0:3a420fc22672 470
CCastrop1012 0:3a420fc22672 471 // Se Reinicializa el Periodo y el Ciclo útil de la señal PWM
CCastrop1012 0:3a420fc22672 472 // que va al Buzzer
CCastrop1012 0:3a420fc22672 473 // Buzzer.period_ms(1);
CCastrop1012 0:3a420fc22672 474 // Buzzer.write(0);
CCastrop1012 0:3a420fc22672 475
CCastrop1012 0:3a420fc22672 476
CCastrop1012 0:3a420fc22672 477
CCastrop1012 0:3a420fc22672 478 }
CCastrop1012 0:3a420fc22672 479
CCastrop1012 0:3a420fc22672 480
CCastrop1012 0:3a420fc22672 481
CCastrop1012 0:3a420fc22672 482 void intTimeBuzzer(void)
CCastrop1012 0:3a420fc22672 483 {
CCastrop1012 0:3a420fc22672 484
CCastrop1012 0:3a420fc22672 485 // Se Reinicializa el Periodo y el Ciclo útil de la señal PWM
CCastrop1012 0:3a420fc22672 486 // que va al Buzzer
CCastrop1012 0:3a420fc22672 487 Buzzer.period_ms(1);
CCastrop1012 0:3a420fc22672 488 Buzzer.write(0);
CCastrop1012 0:3a420fc22672 489
CCastrop1012 0:3a420fc22672 490
CCastrop1012 0:3a420fc22672 491 }
CCastrop1012 0:3a420fc22672 492
CCastrop1012 0:3a420fc22672 493
CCastrop1012 0:3a420fc22672 494 void leer_color()
CCastrop1012 0:3a420fc22672 495 {
CCastrop1012 0:3a420fc22672 496 MuestrearCOLOR.attach(NULL, 1.5); // Se Habilita una interrupcion cada 0.6 Segundos para leer el color
CCastrop1012 0:3a420fc22672 497
CCastrop1012 0:3a420fc22672 498 red = SENSOR_COLOR.ReadRed(); // OBTENEMOS EL TIEMPO DEL CICLO UTIL DE LA FRECUENCIA DE SALIDA
CCastrop1012 0:3a420fc22672 499 green = SENSOR_COLOR.ReadGreen();
CCastrop1012 0:3a420fc22672 500 blue = SENSOR_COLOR.ReadBlue();
CCastrop1012 0:3a420fc22672 501 clear = SENSOR_COLOR.ReadClear();
CCastrop1012 0:3a420fc22672 502
CCastrop1012 0:3a420fc22672 503 //printf("RED: %5d GREEN: %5d BLUE: %5d CLEAR: %5d \n ", red, green, blue, clear);
CCastrop1012 0:3a420fc22672 504
CCastrop1012 0:3a420fc22672 505 red *= 2; // Calculamos EL PERIODO de la frecuencia generada por la lectura del fotodiodo rojo
CCastrop1012 0:3a420fc22672 506 blue *= 2; // Calculamos EL PERIODO de la frecuencia generada por la lectura del fotodiodo rojo
CCastrop1012 0:3a420fc22672 507 green *= 2; // Calculamos EL PERIODO de la frecuencia generada por la lectura del fotodiodo rojo
CCastrop1012 0:3a420fc22672 508 clear *= 2; // Calculamos EL PERIODO de la frecuencia generada por la lectura del fotodiodo rojo
CCastrop1012 0:3a420fc22672 509
CCastrop1012 0:3a420fc22672 510 //printf("RED: %5d GREEN: %5d BLUE: %5d CLEAR: %5d \n ", red, green, blue, clear);
CCastrop1012 0:3a420fc22672 511
CCastrop1012 0:3a420fc22672 512
CCastrop1012 0:3a420fc22672 513 //////////////////////////////////////////////////////////////
CCastrop1012 0:3a420fc22672 514 //// identificar azul
CCastrop1012 0:3a420fc22672 515
CCastrop1012 0:3a420fc22672 516
CCastrop1012 0:3a420fc22672 517 if(red <=42 && red >=24)
CCastrop1012 0:3a420fc22672 518 {
CCastrop1012 0:3a420fc22672 519 if(green >= 20 && green <= 28 )
CCastrop1012 0:3a420fc22672 520 {
CCastrop1012 0:3a420fc22672 521 if(blue >= 10 && blue <= 16)
CCastrop1012 0:3a420fc22672 522 {
CCastrop1012 0:3a420fc22672 523 color_identificado = CMD_azul;
CCastrop1012 0:3a420fc22672 524 CoolTerm.putc( iniciar_telemetria);
CCastrop1012 0:3a420fc22672 525 CoolTerm.putc( CMD_azul );
CCastrop1012 0:3a420fc22672 526 if (color_anterior != CMD_azul)
CCastrop1012 0:3a420fc22672 527 {
CCastrop1012 0:3a420fc22672 528 foregroundColor = FOREGROUND_COLORS[0]; // white
CCastrop1012 0:3a420fc22672 529 backgroundColor = BACKGROUND_COLORS[3];// DarkCyan
CCastrop1012 0:3a420fc22672 530 tft->background(backgroundColor); // set background to black
CCastrop1012 0:3a420fc22672 531 tft->set_font((unsigned char*) Arial24x23,32,127,false); //variable width disabled
CCastrop1012 0:3a420fc22672 532 tft->cls();
CCastrop1012 0:3a420fc22672 533 tft->locate(80,80);
CCastrop1012 0:3a420fc22672 534 tft->printf("COLOR \n\tAZUL\r\n");
CCastrop1012 0:3a420fc22672 535
CCastrop1012 0:3a420fc22672 536 }
CCastrop1012 0:3a420fc22672 537 color_anterior = CMD_azul;
CCastrop1012 0:3a420fc22672 538
CCastrop1012 0:3a420fc22672 539 }
CCastrop1012 0:3a420fc22672 540 }
CCastrop1012 0:3a420fc22672 541 }
CCastrop1012 0:3a420fc22672 542
CCastrop1012 0:3a420fc22672 543
CCastrop1012 0:3a420fc22672 544
CCastrop1012 0:3a420fc22672 545
CCastrop1012 0:3a420fc22672 546 /////////////////////////////////////////////////////////////
CCastrop1012 0:3a420fc22672 547 /// identificar rojo
CCastrop1012 0:3a420fc22672 548 if(red <= 12 )
CCastrop1012 0:3a420fc22672 549 {
CCastrop1012 0:3a420fc22672 550 if(green >= 10 && green <= 28 )
CCastrop1012 0:3a420fc22672 551 {
CCastrop1012 0:3a420fc22672 552 if(blue >= 18 && blue <= 24)
CCastrop1012 0:3a420fc22672 553 {
CCastrop1012 0:3a420fc22672 554 color_identificado = CMD_rojo;
CCastrop1012 0:3a420fc22672 555 CoolTerm.putc( iniciar_telemetria);
CCastrop1012 0:3a420fc22672 556 CoolTerm.putc( CMD_rojo );
CCastrop1012 0:3a420fc22672 557
CCastrop1012 0:3a420fc22672 558 if (color_anterior != CMD_rojo)
CCastrop1012 0:3a420fc22672 559 {
CCastrop1012 0:3a420fc22672 560 foregroundColor = FOREGROUND_COLORS[0]; // white
CCastrop1012 0:3a420fc22672 561 backgroundColor = BACKGROUND_COLORS[6];// DarkCyan
CCastrop1012 0:3a420fc22672 562 tft->background(backgroundColor); // set background to black
CCastrop1012 0:3a420fc22672 563 tft->set_font((unsigned char*) Arial24x23,32,127,false); //variable width disabled
CCastrop1012 0:3a420fc22672 564 tft->cls();
CCastrop1012 0:3a420fc22672 565 tft->locate(80,80);
CCastrop1012 0:3a420fc22672 566 tft->printf("COLOR \n\tROJO\r\n");
CCastrop1012 0:3a420fc22672 567 }
CCastrop1012 0:3a420fc22672 568 color_anterior = CMD_rojo;
CCastrop1012 0:3a420fc22672 569 }
CCastrop1012 0:3a420fc22672 570 }
CCastrop1012 0:3a420fc22672 571
CCastrop1012 0:3a420fc22672 572 if(green < 10 && green >= 6 )
CCastrop1012 0:3a420fc22672 573 {
CCastrop1012 0:3a420fc22672 574 if(blue <= 12 )
CCastrop1012 0:3a420fc22672 575 {
CCastrop1012 0:3a420fc22672 576 color_identificado = CMD_clear;
CCastrop1012 0:3a420fc22672 577 CoolTerm.putc( iniciar_telemetria);
CCastrop1012 0:3a420fc22672 578 CoolTerm.putc( CMD_clear );
CCastrop1012 0:3a420fc22672 579 if (color_anterior != CMD_clear)
CCastrop1012 0:3a420fc22672 580 {
CCastrop1012 0:3a420fc22672 581 foregroundColor = FOREGROUND_COLORS[0]; // white
CCastrop1012 0:3a420fc22672 582 backgroundColor = BACKGROUND_COLORS[2];// DarkCyan
CCastrop1012 0:3a420fc22672 583 tft->background(backgroundColor); // set background to black
CCastrop1012 0:3a420fc22672 584 tft->set_font((unsigned char*) Arial24x23,32,127,false); //variable width disabled
CCastrop1012 0:3a420fc22672 585 tft->cls();
CCastrop1012 0:3a420fc22672 586 tft->locate(80,80);
CCastrop1012 0:3a420fc22672 587 tft->printf("COLOR \n\tAMARILLO\r\n");
CCastrop1012 0:3a420fc22672 588 }
CCastrop1012 0:3a420fc22672 589 color_anterior = CMD_clear;
CCastrop1012 0:3a420fc22672 590
CCastrop1012 0:3a420fc22672 591 }
CCastrop1012 0:3a420fc22672 592
CCastrop1012 0:3a420fc22672 593 }
CCastrop1012 0:3a420fc22672 594
CCastrop1012 0:3a420fc22672 595 }
CCastrop1012 0:3a420fc22672 596
CCastrop1012 0:3a420fc22672 597
CCastrop1012 0:3a420fc22672 598 if(green >= 36 && green <= 44 )
CCastrop1012 0:3a420fc22672 599 {
CCastrop1012 0:3a420fc22672 600 if(red >= 40 && red <= 50 )
CCastrop1012 0:3a420fc22672 601
CCastrop1012 0:3a420fc22672 602 {
CCastrop1012 0:3a420fc22672 603 color_identificado = CMD_verde;
CCastrop1012 0:3a420fc22672 604 CoolTerm.putc( iniciar_telemetria);
CCastrop1012 0:3a420fc22672 605 CoolTerm.putc( CMD_verde );
CCastrop1012 0:3a420fc22672 606 if (color_anterior != CMD_verde)
CCastrop1012 0:3a420fc22672 607 {
CCastrop1012 0:3a420fc22672 608 foregroundColor = FOREGROUND_COLORS[0]; // white
CCastrop1012 0:3a420fc22672 609 backgroundColor = BACKGROUND_COLORS[1];// DarkCyan
CCastrop1012 0:3a420fc22672 610 tft->background(backgroundColor); // set background to black
CCastrop1012 0:3a420fc22672 611 tft->set_font((unsigned char*) Arial24x23,32,127,false); //variable width disabled
CCastrop1012 0:3a420fc22672 612 tft->cls();
CCastrop1012 0:3a420fc22672 613 tft->locate(80,80);
CCastrop1012 0:3a420fc22672 614 tft->printf("COLOR \n\tVERDE\r\n");
CCastrop1012 0:3a420fc22672 615 }
CCastrop1012 0:3a420fc22672 616 color_anterior = CMD_verde;
CCastrop1012 0:3a420fc22672 617 }
CCastrop1012 0:3a420fc22672 618 }
CCastrop1012 0:3a420fc22672 619
CCastrop1012 0:3a420fc22672 620 if (color_identificado == ColorNoIdentificado)
CCastrop1012 0:3a420fc22672 621 {
CCastrop1012 0:3a420fc22672 622
CCastrop1012 0:3a420fc22672 623
CCastrop1012 0:3a420fc22672 624 CoolTerm.putc( iniciar_telemetria);
CCastrop1012 0:3a420fc22672 625 CoolTerm.putc( ColorNoIdentificado);
CCastrop1012 0:3a420fc22672 626
CCastrop1012 0:3a420fc22672 627 if (color_anterior != ColorNoIdentificado)
CCastrop1012 0:3a420fc22672 628 {
CCastrop1012 0:3a420fc22672 629 foregroundColor = FOREGROUND_COLORS[0]; // white
CCastrop1012 0:3a420fc22672 630 backgroundColor = BACKGROUND_COLORS[5];// DarkCyan
CCastrop1012 0:3a420fc22672 631 tft->background(backgroundColor); // set background to black
CCastrop1012 0:3a420fc22672 632 tft->set_font((unsigned char*) Arial24x23,32,127,false); //variable width disabled
CCastrop1012 0:3a420fc22672 633 tft->cls();
CCastrop1012 0:3a420fc22672 634 tft->locate(80,80);
CCastrop1012 0:3a420fc22672 635 tft->printf("COLOR \n\t\t NO \n\tIDENTIFICADO \r\n");
CCastrop1012 0:3a420fc22672 636 }
CCastrop1012 0:3a420fc22672 637 color_anterior = ColorNoIdentificado;
CCastrop1012 0:3a420fc22672 638
CCastrop1012 0:3a420fc22672 639 }
CCastrop1012 0:3a420fc22672 640
CCastrop1012 0:3a420fc22672 641 color_identificado = ColorNoIdentificado;
CCastrop1012 0:3a420fc22672 642
CCastrop1012 0:3a420fc22672 643 MuestrearCOLOR.attach(&leer_color, 1.5); // Se Habilita una interrupcion cada 0.6 Segundos para leer el color
CCastrop1012 0:3a420fc22672 644 }
CCastrop1012 0:3a420fc22672 645
CCastrop1012 0:3a420fc22672 646
CCastrop1012 0:3a420fc22672 647