#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <math.h>
#define ANCHO_PANTALLA 128
#define ALTO_PANTALLA 64
#define OLED_RESET -1
#define DIRECCION_PANTALLA 0x3C//Dirección de comunicacion: 0x3C para 128x64, 0x3D para 128x32
Adafruit_SSD1306 display(ANCHO_PANTALLA, ALTO_PANTALLA, &Wire, OLED_RESET);
//Salidas de control del puente
#define pol1 19 //Salida principal
#define pol2 18 //Salida secundaria
//Constantes para el control del puente
int tonPWM = 0; //Tiempo encendido
int toffPWM = 0; //Tiempo apagado
int tpol = 0; //Tiempo entre cambios de polaridad
int tsec = 100; //Tiempo de seguridad para el cambio de polaridad
int CasoE = 0; //Caso de operación
float N = 0; //Parametro de ajuste
//Botones
#define BUTTON_UP_PIN 12 //Boton arriba
#define BUTTON_DOWN_PIN 13 //Boton Abajo
#define BUTTON_RIGHT_PIN 27 //Boton para mas
#define BUTTON_LEFT_PIN 26 //Boton para menos
#define BUTTON_SELECT_PIN 14 //Boton para seleccionar
//Variables para el control de los menús
int menpal = 0; //Parametro de control del menú principal
int menconfig = 0; //Parametro de control del menú de configuración
int menumod = 0; //Parametro de control del menú Modo de operación
int menugrafic = 0; //Parametro de control del menú de gráficos
int PWMcon = 0; //Parametro de control del menú configuracion de ancho de pulzo
int Polcon = 0; //Parametro de control del menú configuracion de cambio de polaridad
//Parametros para la configuracion del tiempo en horas, min S y mS
int PWMonH = 0;
int PWMonMin = 0;
int PWMonS = 0;
int PWMonmS = 0;
int PWMoffH = 0;
int PWMoffMin = 0;
int PWMoffS = 0;
int PWMoffmS = 0;
int PolH = 0;
int PolMin = 0;
int PolS = 0;
int PolmS = 0;
//Parametros de lectura para órdenes en los sub menús
int selecconfig1;//Lectura de accion en el caso 1
int selecconfig2;//Lectura de accion en el caso 2
int selecconfig3;//Lectura de accion en el caso 3
int selecconfig4;//Lectura de accion en el caso 4
int selecconfig5;//Lectura de accion en el caso 5
int botonmas;//Lectura de accion suma
int botonmenos;//Lectura de accion resta
TaskHandle_t Tarea0; // Tarea0 parpadeo LED 0,3 segundos
TaskHandle_t Tarea1; // Tarea1 parpadeo LED 1 Segundo
TaskHandle_t Tarea2; // Tarea2 Giro Motor Lento
TaskHandle_t Tarea3; // Tarea3 Giro Motor Rapido
TaskHandle_t Tarea4;
const unsigned char PROGMEM logo1[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0x84, 0x18, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0x04, 0x18, 0x3f, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0x04, 0x18, 0x0f, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xf3, 0x04, 0x18, 0x07, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe3, 0x04, 0x18, 0x03, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xc3, 0x04, 0x18, 0x01, 0xff, 0xfc,
0x00, 0x22, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x0f, 0xff, 0xc3, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0x22, 0x21, 0x04, 0x6c, 0x1d, 0x8e, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0x22, 0xd5, 0x2a, 0x49, 0xac, 0x5a, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x22, 0x94, 0xba, 0x49, 0xe4, 0x52, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x22, 0x94, 0xc8, 0x45, 0xef, 0x52, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x1c, 0x94, 0xce, 0x4d, 0xbd, 0xde, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x30, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x3f, 0xff, 0xfc,
0x00, 0x80, 0x20, 0x00, 0x00, 0x20, 0x40, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0xb8, 0xe9, 0x3e, 0xf3, 0x21, 0xce, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0xa5, 0x29, 0x44, 0xd0, 0xa3, 0x5a, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0xa5, 0x29, 0x24, 0x93, 0xa2, 0x5e, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0xa5, 0x29, 0x14, 0x96, 0xa2, 0x58, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0xa4, 0xe7, 0x76, 0x93, 0xa1, 0xce, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x1f, 0xe0, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x1f, 0xe0, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x60, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x40, 0x01, 0x00, 0x02, 0x00, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0xc7, 0x3b, 0xbb, 0xde, 0x67, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x61, 0x29, 0x0a, 0x52, 0x94, 0x00, 0x0f, 0xff, 0x83, 0x04, 0x18, 0x20, 0xff, 0xfc,
0x00, 0x00, 0x15, 0x2d, 0x2a, 0x52, 0xd4, 0x00, 0x0f, 0xff, 0x80, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0x00, 0x95, 0x2d, 0x4a, 0x52, 0x84, 0x00, 0x0f, 0xff, 0x80, 0x04, 0x18, 0x00, 0xff, 0xfc,
0x00, 0x00, 0x67, 0x01, 0xba, 0x0c, 0x60, 0x00, 0x0f, 0xff, 0xc0, 0x04, 0x18, 0x01, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x04, 0x18, 0x03, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x04, 0x18, 0x07, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xfc, 0x04, 0x18, 0x0f, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xfe, 0x04, 0x18, 0x3f, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0x84, 0x18, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
// Representación en bytes del primer logotipo
};
const unsigned char PROGMEM logo2[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0x83, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x3f, 0xc1, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x38, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x1f, 0xff, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x7f, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x7f, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x0c, 0x03, 0x00, 0x7c, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x3c, 0x0f, 0x80, 0x40, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0xe0, 0xff, 0x80, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc3, 0x07, 0xff, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x1c, 0x7f, 0xfb, 0x80, 0x7f, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x61, 0xfc, 0x01, 0xc0, 0x7f, 0xff, 0x80, 0x03, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x05, 0xe0, 0x01, 0xc0, 0x7f, 0x80, 0x83, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x78, 0x00, 0x01, 0xc0, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x01, 0xc0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x03, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x80, 0x07, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x03, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x03, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x03, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xc7, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x60, 0x0f, 0xff, 0xbf, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3f, 0x3f, 0xff, 0xe0, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x03, 0x3f, 0xff, 0xff, 0xc0, 0x00, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x01, 0xf8, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x01, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xff, 0xfc, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xfe, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xe0, 0x3f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0x83, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x83, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff
// Representación en bytes del segundo logotipo
};
const unsigned char PROGMEM logo3[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xfe, 0x00, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x10, 0x10, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xf8, 0x18, 0x30, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0c, 0x00, 0x00, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x06, 0x00, 0x00, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x1f, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x30, 0x00, 0x00, 0x0e, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x01, 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x01, 0x80, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x70, 0x00, 0x00, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0xf8, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0e, 0x00, 0x00, 0x60, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x71, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x0c, 0x18, 0x1f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x1c, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x18, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x18, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x1c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x0e, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x38, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x01, 0x80, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0xc0, 0x0f, 0x80, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00
// Representación en bytes del tercer logotipo
};
void showLogo(const uint8_t* logo, int duration) {
display.clearDisplay();
display.drawBitmap(0, 0, logo, ANCHO_PANTALLA, ALTO_PANTALLA, WHITE);
display.display();
delay(duration);
}
void setup() {
Serial.begin(115200);
//Asignacion de salidas
pinMode(23,OUTPUT);//Salida de funcionamiento
pinMode(4,OUTPUT);//Salida de Parada de emergencia
pinMode(2,OUTPUT);//Salida de led de funcionamiento
pinMode(18,OUTPUT);//Salida de polaridad secundaria
pinMode(19,OUTPUT);//Salida de polaridad primaria
if(!display.begin(SSD1306_SWITCHCAPVCC, DIRECCION_PANTALLA)) {
Serial.println(F("Fallo en la asignacion de SSD1306"));
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println("INTERCAMBIADOR DE POLARIDAD");
display.display();
delay(2000); // Esperar 2 segundos al inicio
// Mostrar el primer logotipo durante 3 segundos
showLogo(logo1, 3000);
// Mostrar el segundo logotipo durante 3 segundos
showLogo(logo2, 3000);
// Mostrar el tercer logotipo durante 3 segundos
showLogo(logo3, 3000);
pinMode(BUTTON_UP_PIN, INPUT_PULLUP);
pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP);
pinMode(BUTTON_RIGHT_PIN, INPUT_PULLUP);
pinMode(BUTTON_LEFT_PIN, INPUT_PULLUP);
pinMode(BUTTON_SELECT_PIN, INPUT_PULLUP);
xTaskCreatePinnedToCore(loop0,"Tarea_0",1000,NULL,1,&Tarea0,0); // Core 0
xTaskCreatePinnedToCore(loop1,"Tarea_1",1000,NULL,2,&Tarea1,1); // Core 1
xTaskCreatePinnedToCore(loop2,"Tarea_2",1000,NULL,2,&Tarea2,1); // Core 1
xTaskCreatePinnedToCore(loop3,"Tarea_3",1000,NULL,2,&Tarea3,1); // Core 1
xTaskCreatePinnedToCore(loop4,"Tarea_4",1000,NULL,1,&Tarea4,1); // Core 1
}
void loop() { //Tarea principal en el nucleo
//
selecconfig3 = digitalRead(BUTTON_SELECT_PIN);
selecconfig1 = digitalRead(BUTTON_SELECT_PIN);
selecconfig2 = digitalRead(BUTTON_SELECT_PIN);
selecconfig4 = digitalRead(BUTTON_SELECT_PIN);
selecconfig5 = digitalRead(BUTTON_SELECT_PIN);
botonmas = digitalRead(BUTTON_RIGHT_PIN);
botonmenos = digitalRead(BUTTON_LEFT_PIN);
//Formulación en pantalla de los menú
if(menconfig == 0 && menumod == 0 && menugrafic == 0 && PWMcon == 0 && Polcon == 0){
updateMenu();
}
if(menconfig != 0 && menumod == 0 && menugrafic == 0){
executeMenuconfig();
}
if(menconfig == 0 && menumod != 0 && menugrafic == 0){
executeMenumod();
}
if(menconfig == 0 && menumod == 0 && menugrafic != 0){
executeMenugrafic();
}
if(PWMcon != 0){
executePWMcon();
}
if(Polcon != 0){
executePOLcon();
}
int buttonState;
// Leer el estado de los botones
buttonState = digitalRead(BUTTON_UP_PIN);
if (buttonState == LOW) {//Movimiento de los menú hacia arriba
if(menconfig == 0 && menumod == 0 && menugrafic == 0 && PWMcon == 0 && Polcon == 0){
menpal = (menpal - 1 + 4) % 4;
}
else if(menconfig != 0 && menumod == 0 && menugrafic == 0){
menconfig = (menconfig - 1 + 6) % 6;
//Acotamos el menú configuración
if(menconfig == 5){
menconfig = 2;
}
if (menconfig ==1){
menconfig=4;
}
}
else if (menconfig == 0 && menumod != 0 && menugrafic == 0){
menumod = (menumod - 1 + 6) % 6;
if(menumod == 5){
menumod = 2;
}
if (menumod ==1){
menumod=4;
}
}
else if (menconfig == 0 && menumod == 0 && menugrafic != 0){
menugrafic = (menugrafic - 1 + 8) % 8;
if(menugrafic == 7){
menugrafic = 2;
}
if (menugrafic ==1){
menugrafic=6;
}
}
else if (PWMcon != 0){
PWMcon = (PWMcon - 1 + 12) % 12;
if(PWMcon == 11){
PWMcon = 2;
}
if (PWMcon ==1){
PWMcon=10;
}
}
else if (Polcon != 0){
Polcon = (Polcon - 1 + 8) % 8;
if(Polcon == 7){
Polcon = 2;
}
if (Polcon ==1){
Polcon=6;
}
}
delay(200);
}
buttonState = digitalRead(BUTTON_DOWN_PIN);
if (buttonState == LOW) {//Movimiento de los menú hacia abajo
if(menconfig == 0 && menumod == 0 && menugrafic == 0 && PWMcon == 0 && Polcon == 0){
menpal = (menpal + 1) % 4;
}
if(menconfig != 0 && menumod == 0 && menugrafic == 0 ){
menconfig = (menconfig + 1) % 6;
if(menconfig == 1 || menconfig == 5){
menconfig = 2;
}
}
if (menconfig == 0 && menumod != 0 && menugrafic == 0){
menumod = (menumod + 1) % 6;
if(menumod == 1 || menumod == 5){
menumod = 2;
}
}
if (menconfig == 0 && menumod == 0 && menugrafic != 0){
menugrafic = (menugrafic + 1) % 8;
if(menugrafic == 1 || menugrafic == 7){
menugrafic = 2;
}
}
if (PWMcon != 0){
PWMcon = (PWMcon + 1) % 12;
if(PWMcon == 1 || PWMcon == 11){
PWMcon = 2;
}
}
if (Polcon != 0){
Polcon = (Polcon + 1) % 8;
if(Polcon == 1 || Polcon == 7){
Polcon = 2;
}
}
delay(200);
}
buttonState = digitalRead(BUTTON_SELECT_PIN);
if (buttonState == LOW) {
if(menpal == 0 && menconfig == 0 && PWMcon == 0 && Polcon == 0){
menconfig = 2;
}
if(menpal == 1 && menumod == 0){
menumod = 2;
}
if (menpal == 2 && menugrafic == 0){
menugrafic = 2;
}
if (menpal == 3){
executeInfo();
}
delay(200);
}
}
void loop0(void *parameter){ // Tarea0 Lectura de Datos eléctricos
while(1==1){
Serial.print("PWMcon = "); Serial.println(PWMcon);
delay(5000);
}
}
void loop1(void *parameter){ // Tarea1 Entrega de datos al puerto serial (Mantenimiento)
while(1==1){
Serial.print("Polcon = "); Serial.println(Polcon);
Serial.print("Mpal = ");Serial.print(menpal); Serial.print(" menconfig = ");Serial.print(menconfig); Serial.print(" modo = ");Serial.print(menumod); Serial.print(" grafic = ");Serial.println(menugrafic);
Serial.print("TonPWM = ");Serial.print(tonPWM); Serial.print(" ToffPWM = ");Serial.print(toffPWM); Serial.print(" Tpol = ");Serial.print(tpol); Serial.print(" N = ");Serial.println(N);
delay(5000);
}
}
void loop2(void *parameter){ // Tarea2 Luz de Operacion y funcion parada de emergencia
while(1==1){
//Modo de prueba
if (PWMonH == 0 && PWMonMin == 0 && PWMonS == 0 && PWMonmS == 0 && PWMoffH == 0 && PWMoffMin == 0 && PWMoffS == 0 && PWMoffmS == 0 && PolH == 0 && PolMin == 0 && PolS == 0 && PolmS == 0){
tonPWM = 300;
toffPWM = 200;
tpol = 6000;
}else {//Modo de operacion real
tonPWM = (PWMonH * 3600000) + (PWMonMin * 60000) + (PWMonS * 1000 ) + (PWMonmS);
toffPWM = (PWMoffH * 3600000) + (PWMoffMin * 60000) + (PWMoffS * 1000 ) + (PWMoffmS);
tpol = (PolH * 3600000) + (PolMin * 60000) + (PolS * 1000) + (PolmS);
}
N = tpol/(tonPWM + toffPWM);
//Luz de Parada de emergencia
if (CasoE == 0){
digitalWrite(4, HIGH);
delay(700);
digitalWrite(4, LOW);
delay(700);
}
//Luz de operacion
if (CasoE > 0){
digitalWrite(23, HIGH);
delay(700);
digitalWrite(23, LOW);
delay(700);
}
}
}
void loop3(void *parameter){ // Tarea3 loop de luz funcionamiento
while(1==1){
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
delay(500);
}
}
void loop4(void *parameter){ // Tarea4 Operacion en casos de estudio
while(1==1){
if(CasoE == 1) {
digitalWrite(pol2, LOW);
digitalWrite(pol1, HIGH);
delay(tonPWM);
digitalWrite(pol1, LOW);
delay(toffPWM);
}
if (CasoE == 2) {
digitalWrite(pol2, LOW);
delay(tsec);
digitalWrite(pol1, HIGH);
delay(tpol);
digitalWrite(pol1, LOW);
delay(tsec);
digitalWrite(pol2, HIGH);
delay(tpol);
}
if (CasoE == 3) {
if(tpol >= tonPWM+toffPWM) {
digitalWrite(4, LOW);
for (int i = 1; i <= N*2; i++) {
digitalWrite(pol2, LOW);
digitalWrite(pol1, HIGH);
delay(tonPWM);
digitalWrite(pol1, LOW);
delay(toffPWM);
i=i+1;
}
for (int j = 1; j <= N*2; j++) {
digitalWrite(pol1, LOW);
digitalWrite(pol2, HIGH);
delay(tonPWM);
digitalWrite(pol2, LOW);
delay(toffPWM);
j=j+1;
}
}else {
digitalWrite(4, HIGH);
}
}
}
}
void updateMenu() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(":::::::::::::::::::::");
display.println(" MENU PRINCIPAL");
display.println(":::::::::::::::::::::");
display.setTextSize(1);
switch (menpal) {
case 0:
display.println("> Configuracion");
display.println(" Modo de trabajo");
display.println(" Graficos");
display.println(" Acerca de...");
break;
case 1:
display.println(" Configuracion");
display.println("> Modo de trabajo");
display.println(" Graficos");
display.println(" Acerca de...");
break;
case 2:
display.println(" Configuracion");
display.println(" Modo de trabajo");
display.println("> Graficos");
display.println(" Acerca de...");
break;
case 3:
display.println(" Configuracion");
display.println(" Modo de trabajo");
display.println(" Graficos");
display.println("> Acerca de...");
break;
}
display.display();
}
void executeMenuconfig(){
display.clearDisplay();
display.setCursor(0, 0);
display.println(":::::::::::::::::::::");
display.println(" CONFIGURACION");
display.println(":::::::::::::::::::::");
display.setTextSize(1);
switch (menconfig) {
case 2:
display.println("> Parametros PMW");
display.println(" Parametro Polaridad");
display.println(" Regresar");
if (selecconfig1 == LOW){
menpal = 0;
menconfig = 0;
PWMcon= 2;
delay(200);
}
break;
case 3:
display.println(" Parametros PMW");
display.println("> Parametro Polaridad");
display.println(" Regresar");
if (selecconfig2 == LOW){
menpal = 0;
menconfig = 0;
Polcon= 2;
}
break;
case 4:
display.println(" Parametros PMW");
display.println(" Parametro Polaridad");
display.println("> Regresar");
if (selecconfig3 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(" >>> Saliendo...");
display.println(":::::::::::::::::::::");
menpal = 0;
menconfig = 0;
display.display();
delay(2000);
}
break;
}
display.display();
}
void executeMenumod(){
display.clearDisplay();
display.setCursor(0, 0);
display.println(":::::::::::::::::::::");
display.println(" MODO DE OPERACION");
display.println(":::::::::::::::::::::");
display.setTextSize(1);
switch (menumod) {
case 2:
display.println("> Modo PMW");
display.println(" Modo Polaridad");
display.println(" Modo combinado");
if (selecconfig1 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(" >>> Cambiando a PWM");
display.println(":::::::::::::::::::::");
menpal = 0;
menumod = 0;
CasoE = 1;
display.display();
delay(2000);
}
break;
case 3:
display.println(" Modo PMW");
display.println("> Modo Polaridad");
display.println(" Modo combinado");
if (selecconfig2 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(">>>Cambio a Polaridad");
display.println(":::::::::::::::::::::");
menpal = 0;
menumod = 0;
CasoE = 2;
display.display();
delay(2000);
}
break;
case 4:
display.println(" Modo PMW");
display.println(" Modo Polaridad");
display.println("> Modo combinado");
if (selecconfig3 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(">>>Cambio a Combinado");
display.println(":::::::::::::::::::::");
menpal = 0;
menumod = 0;
CasoE = 3;
display.display();
delay(2000);
}
break;
}
display.display();
}
void executeMenugrafic(){
display.clearDisplay();
display.setCursor(0, 0);
display.println(":::::::::::::::::::::");
display.println(" GRAFICOS");
display.println(":::::::::::::::::::::");
display.setTextSize(1);
switch (menugrafic) {
case 2:
display.println("> Tension");
display.println(" Corriente");
display.println(" Grafico Lissajous");
display.println(" Potencia");
display.println(" Regresar");
if (selecconfig1 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(" >>> Cambiando a PWM");
display.println(":::::::::::::::::::::");
menpal = 0;
menugrafic = 0;
CasoE = 1;
display.display();
delay(2000);
}
break;
case 3:
display.println(" Tension");
display.println("> Corriente");
display.println(" Grafico Lissajous");
display.println(" Potencia");
display.println(" Regresar");
if (selecconfig2 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(">>>Cambio a Polaridad");
display.println(":::::::::::::::::::::");
menpal = 0;
menugrafic = 0;
CasoE = 2;
display.display();
delay(2000);
}
break;
case 4:
display.println(" Tension");
display.println(" Corriente");
display.println("> Grafico Lissajous");
display.println(" Potencia");
display.println(" Regresar");
if (selecconfig3 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(">>>Cambio a Combinado");
display.println(":::::::::::::::::::::");
menpal = 0;
menugrafic = 0;
CasoE = 3;
display.display();
delay(2000);
}
break;
case 5:
display.println(" Tension");
display.println(" Corriente");
display.println(" Grafico Lissajous");
display.println("> Potencia");
display.println(" Regresar");
if (selecconfig4 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(">>>Cambio a Polaridad");
display.println(":::::::::::::::::::::");
menpal = 0;
menugrafic = 0;
CasoE = 2;
display.display();
delay(2000);
}
break;
case 6:
display.println(" Tension");
display.println(" Corriente");
display.println(" Grafico Lissajous");
display.println(" Potencia");
display.println("> Regresar");
if (selecconfig5 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(">>>Cambio a Polaridad");
display.println(":::::::::::::::::::::");
menpal = 0;
menugrafic = 0;
CasoE = 2;
display.display();
delay(2000);
}
break;
}
display.display();
}
void executeInfo(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(":::::::::::::::::::::");
display.println(" info");
display.println(":::::::::::::::::::::");
display.display();
delay(20);
}
void executePWMcon(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(" MODULACION PWM");
display.println(":::::::::::::::::::::");
display.println(" ON OFF");
switch (PWMcon) {
case 2:
display.print("Horas >");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMonH = PWMonH + 1;
delay(200);
}
if (botonmenos == LOW){
PWMonH = PWMonH - 1;
delay(200);
}
if (PWMonH > 24 || PWMonH < 0){
PWMonH = 0;
}
break;
case 3:
display.print("Horas ");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos >");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMonMin = PWMonMin + 1;
delay(200);
}
if (botonmenos == LOW){
PWMonMin = PWMonMin - 1;
delay(200);
}
if (PWMonMin > 60){
PWMonMin = 0;
PWMonH = PWMonH + 1;
}
if(PWMonMin < 0){
PWMonMin = 0;
}
break;
case 4:
display.print("Horas ");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos >");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMonS = PWMonS + 1;
delay(200);
}
if (botonmenos == LOW){
PWMonS = PWMonS - 1;
delay(200);
}
if (PWMonS > 60){
PWMonS = 0;
PWMonMin = PWMonMin + 1;
}
if(PWMonS < 0){
PWMonS = 0;
}
break;
case 5:
display.print("Horas ");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S >");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMonmS = PWMonmS + 10;
delay(200);
}
if (botonmenos == LOW){
PWMonmS = PWMonmS - 10;
delay(200);
}
if (PWMonmS >= 1000){
PWMonmS = 0;
PWMonS = PWMonS + 1;
}
if(PWMonmS < 0){
PWMonmS = 0;
}
break;
case 6:
display.print("Horas ");display.print(PWMonH);display.print(" >");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMoffH = PWMoffH + 1;
delay(200);
}
if (botonmenos == LOW){
PWMoffH = PWMoffH - 1;
delay(200);
}
if (PWMoffH > 24 || PWMoffH < 0){
PWMoffH = 0;
}
break;
case 7:
display.print("Horas ");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" >");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMoffMin = PWMoffMin + 1;
delay(200);
}
if (botonmenos == LOW){
PWMoffMin = PWMoffMin - 1;
delay(200);
}
if (PWMoffMin > 60){
PWMoffMin = 0;
PWMoffH = PWMoffH + 1;
}
if(PWMoffMin < 0){
PWMoffMin = 0;
}
break;
case 8:
display.print("Horas ");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" >");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMoffS = PWMoffS + 1;
delay(200);
}
if (botonmenos == LOW){
PWMoffS = PWMoffS - 1;
delay(200);
}
if (PWMoffS > 60){
PWMoffS = 0;
PWMoffMin = PWMoffMin + 1;
}
if(PWMoffS < 0){
PWMoffS = 0;
}
break;
case 9:
display.print("Horas ");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" >");display.println(PWMoffmS);
display.println(" Regresar");
if (botonmas == LOW){
PWMoffmS = PWMoffmS + 10;
delay(200);
}
if (botonmenos == LOW){
PWMoffmS = PWMoffmS - 10;
delay(200);
}
if (PWMoffmS >= 1000){
PWMoffmS = 0;
PWMoffS = PWMoffS + 1;
}
if(PWMoffmS < 0){
PWMoffmS = 0;
}
break;
case 10:
display.print("Horas ");display.print(PWMonH);display.print(" ");display.println(PWMoffH);
display.print("Minutos ");display.print(PWMonMin);display.print(" ");display.println(PWMoffMin);
display.print("Segundos ");display.print(PWMonS);display.print(" ");display.println(PWMoffS);
display.print("Mili S ");display.print(PWMonmS);display.print(" ");display.println(PWMoffmS);
display.println(" > Regresar");
if (selecconfig3 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(" >>> Saliendo...");
display.println(":::::::::::::::::::::");
menpal = 0;
menconfig = 2;
PWMcon = 0;
display.display();
delay(2000);
}
break;
}
display.display();
delay(20);
}
void executePOLcon(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(":::::::::::::::::::::");
display.println(" MODULACION POLARIDAD");
display.println(":::::::::::::::::::::");
switch (Polcon) {
case 2:
display.print("Horas >");display.println(PolH);
display.print("Minutos ");display.println(PolMin);
display.print("Segundos ");display.println(PolS);
display.print("Mili S ");display.println(PolmS);
display.println(" Regresar");
if (botonmas == LOW){
PolH = PolH + 1;
delay(200);
}
if (botonmenos == LOW){
PolH = PolH - 1;
delay(200);
}
if (PolH > 24 || PolH < 0){
PolH = 0;
}
break;
case 3:
display.print("Horas ");display.println(PolH);
display.print("Minutos >");display.println(PolMin);
display.print("Segundos ");display.println(PolS);
display.print("Mili S ");display.println(PolmS);
display.println(" Regresar");
if (botonmas == LOW){
PolMin = PolMin + 1;
delay(200);
}
if (botonmenos == LOW){
PolMin = PolMin - 1;
delay(200);
}
if (PolMin > 60){
PolMin = 0;
PolH = PolH + 1;
}
if(PolMin < 0){
PolMin = 0;
}
break;
case 4:
display.print("Horas ");display.println(PolH);
display.print("Minutos ");display.println(PolMin);
display.print("Segundos >");display.println(PolS);
display.print("Mili S ");display.println(PolmS);
display.println(" Regresar");
if (botonmas == LOW){
PolS = PolS + 1;
delay(200);
}
if (botonmenos == LOW){
PolS = PolS - 1;
delay(200);
}
if (PolS > 60){
PolS = 0;
PolMin = PolMin + 1;
}
if(PolS < 0){
PolS = 0;
}
break;
case 5:
display.print("Horas ");display.println(PolH);
display.print("Minutos ");display.println(PolMin);
display.print("Segundos ");display.println(PolS);
display.print("Mili S >");display.println(PolmS);
display.println(" Regresar");
if (botonmas == LOW){
PolmS = PolmS + 10;
delay(200);
}
if (botonmenos == LOW){
PolmS = PolmS - 10;
delay(200);
}
if (PolmS >= 1000){
PolmS = 0;
PolS = PolS + 1;
}
if(PolmS < 0){
PolmS = 0;
}
break;
case 6:
display.print("Horas ");display.println(PolH);
display.print("Minutos ");display.println(PolMin);
display.print("Segundos ");display.println(PolS);
display.print("Mili S ");display.println(PolmS);
display.println(" > Regresar");
if (selecconfig3 == LOW){
display.clearDisplay();
display.setCursor(0, 20);
display.println(":::::::::::::::::::::");
display.println(" >>> Saliendo...");
display.println(":::::::::::::::::::::");
menpal = 0;
menconfig = 2;
Polcon = 0;
display.display();
delay(2000);
}
break;
}
display.display();
delay(20);
}