#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#include "U8glib.h" U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST);
#define BUTTON_UP_PIN 12 // pin para el botón ARRIBA
#define BUTTON_SELECT_PIN 8 // pin para el botón SELECT
#define BUTTON_DOWN_PIN 4 // pin para el botón ABAJO
int button_up_clicked = 0; //solo realice la acción cuando se haga clic en el botón y espere hasta que se presione nuevamente
int button_select_clicked = 0; // Lo mismo que arriba
int button_down_clicked = 0; // Lo mismo que arriba
int item_selected = 0; // qué elemento del menú está seleccionado
int item_sel_previous; // Elemento anterior: se utiliza en la pantalla del menú para dibujar el elemento anterior al seleccionado.
int item_sel_next; // Siguiente elemento: se utiliza en la pantalla del menú para dibujar el siguiente elemento después del seleccionado.
int current_screen = 0; // 0 = menú, 1 = captura de pantalla, 2 = qr
RTC_DS3231 RTC;
const unsigned char epd_bitmap_programacion_menu [] PROGMEM = {
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, 0x02,
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, 0x02,
0x00, 0x03, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x03, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x03, 0x88, 0x60, 0x20, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x06, 0x89, 0xf3, 0x77, 0xf9, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x06, 0x89, 0x1b, 0x97, 0xf9, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0xc8, 0x1b, 0x96, 0xc8, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x04, 0xc9, 0xfb, 0x16, 0x49, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x04, 0xcb, 0x3b, 0x06, 0x4b, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x0f, 0xcb, 0x1b, 0x06, 0x4b, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x0c, 0x4b, 0x1b, 0x04, 0x4b, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x0c, 0x69, 0xfb, 0x04, 0xc9, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
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, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
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, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x02,
0x30, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x02,
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x02,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x02,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02,
0x40, 0x18, 0x60, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x40, 0x18, 0x60, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02,
0xc0, 0x18, 0x63, 0x80, 0x00, 0xe1, 0xd1, 0xc3, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0xc0, 0x18, 0x67, 0xcd, 0xb3, 0xe3, 0xf3, 0xe6, 0x60, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02,
0xc0, 0x18, 0x64, 0x6f, 0xf2, 0x36, 0x32, 0x34, 0x60, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02,
0xc0, 0x18, 0x60, 0x6e, 0xd0, 0x16, 0x10, 0x36, 0x20, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02,
0xc0, 0x18, 0x27, 0xec, 0x99, 0xf4, 0x13, 0xf3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0xc0, 0x08, 0x2c, 0xec, 0x9b, 0x76, 0x16, 0x71, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02,
0xc0, 0x18, 0x2c, 0x6c, 0x9e, 0x16, 0x36, 0x34, 0x60, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02,
0xc0, 0x18, 0x2c, 0x6c, 0x96, 0x32, 0x36, 0x36, 0x60, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x02,
0xe0, 0x1f, 0xe7, 0xec, 0x93, 0xf3, 0xf3, 0xf3, 0xc0, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x02,
0x40, 0x70, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
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, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0xfc, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0xc6, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc6, 0x00, 0x9f, 0x1c, 0x01, 0x83, 0x89, 0x0e, 0x80, 0xe1, 0xc3, 0xc0, 0x00, 0x00, 0x02,
0x00, 0xc6, 0xc4, 0x9b, 0x37, 0x07, 0xe7, 0xcb, 0x9f, 0x93, 0xe3, 0xe7, 0xe0, 0x00, 0x00, 0x02,
0x00, 0xc6, 0xc4, 0xb1, 0xa3, 0x04, 0x2c, 0x4e, 0xf1, 0x93, 0x36, 0x34, 0x20, 0x00, 0x00, 0x02,
0x00, 0xcc, 0x8c, 0x90, 0x61, 0x04, 0x20, 0x6c, 0xf0, 0x90, 0x16, 0x14, 0x20, 0x00, 0x00, 0x00,
0x00, 0xf8, 0x8c, 0x9e, 0x61, 0x0c, 0x07, 0xec, 0xf0, 0x91, 0xf6, 0x04, 0x20, 0x00, 0x00, 0x02,
0x00, 0xc0, 0x8c, 0x87, 0x61, 0x04, 0x0c, 0xec, 0x30, 0x93, 0x36, 0x04, 0x20, 0x00, 0x00, 0x00,
0x00, 0xc0, 0x9c, 0x91, 0x23, 0x04, 0x28, 0x68, 0x31, 0x96, 0x16, 0x14, 0x20, 0x00, 0x00, 0x02,
0x00, 0xc0, 0xdc, 0x9b, 0x32, 0x06, 0x6c, 0xc8, 0x19, 0x96, 0x33, 0x36, 0x60, 0x00, 0x00, 0x02,
0x00, 0xc0, 0x74, 0x9f, 0x1e, 0x03, 0xc7, 0xc8, 0x0f, 0x93, 0xf1, 0xe3, 0xc0, 0x00, 0x00, 0x03,
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, 0x02,
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, 0x02,
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, 0x02
};
// Definir constantes
#define ANCHO_PANTALLA 128 // ancho pantalla OLED
#define ALTO_PANTALLA 64 // alto pantalla OLED
// Objeto de la clase Adafruit_SSD1306
Adafruit_SSD1306 display(ANCHO_PANTALLA, ALTO_PANTALLA, &Wire, -1);
String dia_semana[] = {"Domingo", "Lunes", "martes", "Miercoles", "Jueves", "Viernes", "Sabado"};
char data[16];
void setup()
{
Serial.begin(9600);
Wire.begin();
RTC.begin();
//RTC.adjust(DateTime(__DATE__, __TIME__));
DateTime now = RTC.now();
Serial.println("Iniciando pantalla OLED");
// Iniciar pantalla OLED en la dirección 0x3C
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("No se encuentra la pantalla OLED");
while (true);
}
// Limpir buffer
display.clearDisplay();
// Color del texto
display.setTextColor(SSD1306_WHITE);
// definir pines para botones
// INPUT_PULLUP significa que el botón está ALTO cuando no se presiona y BAJO cuando se presiona
// ya que está conectado entre algún pin y GND
pinMode(BUTTON_UP_PIN, INPUT_PULLUP); // botón de arriba
pinMode(BUTTON_SELECT_PIN, INPUT_PULLUP); // botón de selección
pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP); // botón abajo
}
void loop()
{
DateTime now = RTC.now();
int hora = now.hour();
int minutos = now.minute();
int load = 0;
uint8_t par;
display.fillRoundRect(0, 0, 128, 12, 3, SSD1306_WHITE);
display.setCursor(8, 2);
// Tamaño del texto
display.setTextSize(1);
display.setTextColor(SSD1306_BLACK);
display.print(dia_semana[now.dayOfTheWeek()]);
display.print(" ");
display.print(now.day());
display.print("/");
display.print(now.month());
display.print("/");
display.println(now.year());
display.setTextColor(SSD1306_WHITE);
// Tamaño del texto
display.setTextSize(3);
display.setCursor(15, 20);
display.print(hora);
par = now.second() & 0b1;
if (par)
{
//numero impar
display.print(" ");
}
else
{
//numero par
display.print(":");
}
if (minutos < 10)
{
display.print("0");
}
else
{
// Posición del texto
display.print("");
}
display.print(minutos);
display.drawCircle(117, 48, 10, SSD1306_WHITE);
display.setCursor(112, 45);
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
if (now.second() < 10)
{
display.print("0");
display.print(now.second());
}
else
{
display.println(now.second());
}
load = map(now.second(), 0, 59, 15, 106);
display.drawLine(15, 50, load, 50, SSD1306_WHITE);
// Enviar a pantalla
display.display();
// Limpir buffer
display.clearDisplay();
}