#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
// 'emojiCastelao', 128x64px
const unsigned char epd_bitmap_emojiCastelao [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x66, 0x0e, 0xfe, 0x7f, 0x1e, 0x03, 0xf3, 0x19, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1e, 0x66, 0x0e, 0xfe, 0x7f, 0x1e, 0x03, 0xf3, 0x19, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1e, 0x66, 0x0e, 0xe7, 0x70, 0x1e, 0x03, 0x3b, 0x19, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1e, 0x66, 0x0e, 0xe7, 0x70, 0x1e, 0x07, 0x33, 0x19, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1e, 0x66, 0x0e, 0xe7, 0x70, 0x1e, 0x07, 0x13, 0x9d, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xee, 0x0e, 0xe7, 0x70, 0x36, 0x07, 0x03, 0x19, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1b, 0xe6, 0x0e, 0xe7, 0x7e, 0x37, 0x07, 0x03, 0xfd, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1b, 0xe6, 0x0e, 0xe7, 0x7e, 0x33, 0x07, 0x03, 0xf9, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xe6, 0x0e, 0xe7, 0x70, 0x33, 0x07, 0x03, 0x19, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xee, 0x0e, 0xe7, 0x70, 0x33, 0x07, 0x33, 0x19, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xe6, 0x0e, 0xe7, 0x70, 0x3f, 0x07, 0x33, 0x19, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xe6, 0x0e, 0xe7, 0x70, 0x7f, 0x07, 0x33, 0x19, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0xe6, 0x0e, 0xe7, 0x70, 0x63, 0x83, 0x33, 0x99, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0xe6, 0x0e, 0xfe, 0x7f, 0x63, 0x83, 0xf3, 0x19, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0xe6, 0x0e, 0xfc, 0x7f, 0x61, 0x81, 0xe3, 0x19, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7f, 0xc0, 0xff, 0xc0, 0x00, 0x20, 0x0f, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x00, 0x1b, 0xfc, 0x80, 0x3f, 0xfc, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x00, 0x7b, 0xff, 0xc0, 0x0f, 0xe0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x04, 0xff, 0xff, 0xff, 0xbf, 0xfe, 0xe0, 0x00, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x0c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x08, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3f, 0xe0, 0x3c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x08, 0x7f, 0xff, 0xf7, 0x9f, 0xfe, 0x00, 0xff, 0xbe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x0c, 0x1f, 0xe7, 0xe3, 0x9f, 0xff, 0x80, 0x3f, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x0e, 0x00, 0x0f, 0xc3, 0x9f, 0xe7, 0x84, 0x1f, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0x07, 0x00, 0x1f, 0x83, 0x8f, 0xff, 0x04, 0x3f, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xc3, 0xc0, 0x7f, 0x03, 0x83, 0xfc, 0x08, 0x3c, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x03, 0x80, 0x00, 0x10, 0x78, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x1f, 0xff, 0x80, 0x01, 0xe0, 0x00, 0x20, 0x70, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x81, 0xe0, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xd0, 0x03, 0xc0, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x1f, 0xf0, 0x1f, 0xe0, 0x3f, 0x00, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x0e, 0x01, 0xff, 0xf8, 0x01, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x06, 0x40, 0x80, 0x00, 0x00, 0x03, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x1d, 0xfd, 0xc1, 0x81, 0xfb, 0x03, 0x19, 0xcf, 0x8f, 0xc6, 0x0f, 0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xe7, 0x19, 0xcc, 0x66, 0x0e, 0x60, 0x00, 0x00,
0x00, 0x03, 0x19, 0xfd, 0xfd, 0xf9, 0xf9, 0x81, 0xe7, 0x1f, 0xcc, 0x67, 0xef, 0xe1, 0x80, 0x00,
0x00, 0x03, 0x19, 0xfd, 0xfd, 0xf8, 0xf1, 0x80, 0xe7, 0x0f, 0x8c, 0x67, 0xef, 0xc1, 0x80, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 1040)
const int epd_bitmap_allArray_LEN = 1;
const unsigned char* epd_bitmap_allArray[1] = {
epd_bitmap_emojiCastelao
};
#define OLED_WIDTH 128
#define OLED_HIGHT 64
#define OLED_ADDR 0x3C
#define UP 19
#define DOWN 18
#define ENTER 17
#define RIGHT 4
int firstDigit;
int secondDigit;
int menu;
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HIGHT);
void Menu2() {
display.clearDisplay();
display.setCursor(4, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Calculadora de edad");
display.setTextSize(2);
display.setCursor(0, 20);
display.println("Ingrese");
display.setCursor(0, 37);
display.println("su edad:");
display.fillRect(111, 36, 12, 16, WHITE);
display.setTextColor(WHITE);
display.setCursor(100, 37);
display.println(firstDigit);
display.setTextColor(BLACK);
display.setCursor(112, 37);
display.println(secondDigit);
display.display();
}
void Menu1() {
display.clearDisplay();
display.setCursor(4, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Calculadora de edad");
display.setTextSize(2);
display.setCursor(0, 20);
display.println("Ingrese");
display.setCursor(0, 37);
display.println("su edad:");
display.fillRect(99, 36, 12, 16, WHITE);
display.setTextColor(BLACK);
display.setCursor(100, 37);
display.println(firstDigit);
display.setTextColor(WHITE);
display.setCursor(112, 37);
display.println(secondDigit);
display.display();
}
void DrawProgressBar() {
display.setCursor(12, 12);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Calculando...");
display.drawRect(12, 22, 100, 20, WHITE);
for (int progress = 0; progress < 38; progress++) {
display.fillRect(12, 22, progress, 20, WHITE);
display.display();
}
display.fillRect(12, 22, 87, 20, WHITE);
display.display();
delay(1000);
display.fillRect(12, 22, 112, 20, WHITE);
display.display();
delay(1500);
}
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
pinMode(UP, INPUT_PULLUP);
pinMode(DOWN, INPUT_PULLUP);
pinMode(ENTER, INPUT_PULLUP);
pinMode(RIGHT, INPUT_PULLUP);
firstDigit = 0;
secondDigit = 0;
menu = 0;
}
void loop() {
if(firstDigit > 9) {firstDigit = 0;}
else if(firstDigit < 0) {firstDigit = 9;}
if(secondDigit > 9) {secondDigit = 0;}
else if(secondDigit < 0) {secondDigit = 9;}
if(menu == 0){Menu1();}
else if(menu == 1){Menu2();}
if(!digitalRead(UP) && menu == 0) {
firstDigit = firstDigit + 1;
Menu1();
}
if(!digitalRead(UP) && menu == 1) {
secondDigit = secondDigit + 1;
Menu2();
}
if(!digitalRead(DOWN) && menu == 0) {
firstDigit = firstDigit - 1;
Menu1();
}
if(!digitalRead(DOWN) && menu == 1) {
secondDigit = secondDigit - 1;
Menu2();
}
if(!digitalRead(ENTER)) {
display.clearDisplay();
DrawProgressBar();
display.clearDisplay();
display.drawBitmap(0, 0, epd_bitmap_emojiCastelao, 128, 64, WHITE);
display.display();
delay(10000);
}
if(!digitalRead(RIGHT)) {
if(menu == 0){menu = 1;}
else if(menu == 1){menu = 0;}
}
}