#include <Arduino.h>
#include <U8g2lib.h>
#include "U8glib.h"
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
//U8G2_ST7567_ENH_DG128064I_F_SW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);
const unsigned char epd_bitmap_New_Project_6_2 [] 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, 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, 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, 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, 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, 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, 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, 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,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
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, 0x90, 0x3e, 0x10, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x90, 0x08, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x90, 0x08, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x90, 0x08, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0x08, 0xf0, 0x08, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0x3e, 0xf0, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x08, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0x08, 0xf0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x08, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x08, 0xf0, 0x08, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'et select', 9x6px
const unsigned char epd_bitmap_et_select [] PROGMEM = {
0x00, 0x00, 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x00, 0x00
};
// 'ft select', 9x6px
const unsigned char epd_bitmap_ft_select [] PROGMEM = {
0x00, 0x00, 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x00, 0x00
};
// 'ut select', 9x6px
const unsigned char epd_bitmap_ut_select [] PROGMEM = {
0x00, 0x00, 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x00, 0x00
};
// 'lt select', 9x6px
const unsigned char epd_bitmap_lt_select [] PROGMEM = {
0x00, 0x00, 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 128)
const int epd_bitmap_allArray_LEN = 4;
const unsigned char* epd_bitmap_allArray[4] = {
epd_bitmap_et_select,
epd_bitmap_ft_select,
epd_bitmap_lt_select,
epd_bitmap_ut_select
};
// Define the pin numbers
const int buttonPin1 = 2; // the number of the first button pin
const int buttonPin2 = 3; // the number of the second button pin
const int buttonPin3 = 4; // the number of the third button pin
// Define the menu states
enum MenuState1 {
MENU_VOLTS,
MENU_OUTSIDE_AIR,
};
enum MenuState2 {
MENU_UNIVERSAL_TIME,
MENU_LOCAL_TIME,
MENU_FLIGHT_TIME,
// MENU_COUNTDOWN_TIMER,
MENU_STOPWATCH
};
MenuState1 menuState1 = MENU_VOLTS;
MenuState2 menuState2 = MENU_UNIVERSAL_TIME;
// Initialize the display
//U8G2_ST7567_ENH_DG128064I_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0); // [full framebuffer, size = 1024 bytes]
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
int lastButtonState3 = LOW;
// Variables for the stopwatch
unsigned long stopwatchStart = 0;
unsigned long stopwatchStop = 0;
bool stopwatchRunning = false;
void setup() {
// initialize the display
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
u8g2.setColorIndex(1); // set the color to white
u8g2.setBitmapMode(1);
u8g2.begin();
// initialize the button pins as inputs:
}
void loop() {
// read the state of the buttons:
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);
// check if button1 was pressed. If it was, the buttonState1 is HIGH:
if (lastButtonState1 == LOW && buttonState1 == HIGH) {
delay(25); // delay for 50 milliseconds
// re-read the state of the button:
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 == HIGH) { // if the button is still HIGH after the delay
// change menu state
// check if button1 was pressed. If it was, the buttonState1 is HIGH:
//if (digitalRead(buttonPin1) == LOW) {
// change menu state
switch (menuState1) {
case MENU_VOLTS:
menuState1 = MENU_OUTSIDE_AIR;
break;
case MENU_OUTSIDE_AIR:
menuState1 = MENU_VOLTS;
break;
default:
menuState1 = MENU_VOLTS;
break;
}
}
}
// check if button2 was pressed. If it was, the buttonState2 is HIGH:
if (lastButtonState2 == LOW && buttonState2 == HIGH) {
delay(25); // delay for 50 milliseconds
// re-read the state of the button:
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 == HIGH) { // if the button is still HIGH after the delay
// change menu state
// change menu state
switch (menuState2) {
case MENU_UNIVERSAL_TIME:
menuState2 = MENU_LOCAL_TIME;
break;
case MENU_LOCAL_TIME:
menuState2 = MENU_FLIGHT_TIME;
break;
case MENU_FLIGHT_TIME:
//menuState2 = MENU_COUNTDOWN_TIMER;
menuState2 = MENU_STOPWATCH;
break;
//case MENU_COUNTDOWN_TIMER:
// menuState2 = MENU_STOPWATCH;
//break;
case MENU_STOPWATCH:
menuState2 = MENU_UNIVERSAL_TIME;
break;
}
}
}
// check if button3 was pressed. If it was, the buttonState3 is HIGH:
if (lastButtonState3 == LOW && buttonState3 == HIGH) {
delay(50); // delay for 50 milliseconds
// re-read the state of the button:
buttonState3 = digitalRead(buttonPin3);
if (buttonState3 == HIGH) { // if the button is still HIGH after the delay
// start or stop the stopwatch
if (menuState2 == MENU_STOPWATCH) {
if (stopwatchRunning) {
stopwatchStop = millis();
stopwatchRunning = false;
} else {
stopwatchStart = millis();
stopwatchRunning = true;
}
}
}
}
lastButtonState1 = buttonState1;
lastButtonState2 = buttonState2;
lastButtonState3 = buttonState3;
// update the display based on the current menu state
u8g2.clearBuffer(); // clear the internal memory
switch (menuState1) {
case MENU_VOLTS:
//u8g2.drawStr(0, 10, "Volts Menu");
u8g2.setFont(u8g2_font_freedoomr25_tn);
u8g2.drawStr(20,30,"25");
u8g2.enableUTF8Print();
u8g2.setFont(u8g2_font_inb24_mr);
//u8g2.drawStr(90,30,"");
u8g2.drawStr(60,28,"V");
u8g2.drawXBMP( 0, 0, 128, 64, epd_bitmap_New_Project_6_2 );
break;
case MENU_OUTSIDE_AIR:
//u8g2.drawStr(0, 10, "Outside Air Menu");
u8g2.drawXBMP( 0, 0, 128, 64, epd_bitmap_New_Project_6_2 );
u8g2.setFont(u8g2_font_freedoomr25_tn);
u8g2.drawStr(20,30,"18");
u8g2.enableUTF8Print();
u8g2.setFont(u8g2_font_inb24_mr);
//u8g2.drawStr(90,30,"");
u8g2.drawStr(60,28,"C");
break;
}
switch (menuState2) {
case MENU_UNIVERSAL_TIME:
u8g2.setFont(u8g2_font_freedoomr25_tn);
u8g2.drawStr(35,63,"12");
u8g2.drawStr(70,63,":");
u8g2.drawStr(81,63,"00");
u8g2.drawXBMP( 12, 41, 9, 6, epd_bitmap_ut_select);
//u8g2.drawStr(0, 10, "Universal Time Menu");
u8g2.drawXBMP( 0, 0, 128, 64, epd_bitmap_New_Project_6_2 );
break;
case MENU_LOCAL_TIME:
u8g2.drawXBMP( 0, 0, 128, 64, epd_bitmap_New_Project_6_2 );
u8g2.drawXBMP( 28, 41, 9, 6, epd_bitmap_lt_select);
//u8g2.drawStr(0, 10, "Local Time Menu");
u8g2.setFont(u8g2_font_freedoomr25_tn);
u8g2.drawStr(40,63,"13");
u8g2.drawStr(75,63,":");
u8g2.drawStr(86,63,"00");
break;
case MENU_FLIGHT_TIME:
u8g2.drawXBMP( 0, 0, 128, 64, epd_bitmap_New_Project_6_2 );
u8g2.drawXBMP( 12, 55, 9, 6, epd_bitmap_ft_select);
//u8g2.drawStr(0, 10, "Flight Time Menu");
u8g2.setFont(u8g2_font_freedoomr25_tn);
u8g2.drawStr(40,63,"00");
u8g2.drawStr(75,63,":");
u8g2.drawStr(86,63,"00");
break;
//case MENU_COUNTDOWN_TIMER:
// u8g2.drawXBMP( 0, 0, 128, 64, epd_bitmap_New_Project_6_2 );
// u8g2.drawXBMP( 28, 55, 9, 6, epd_bitmap_et_select);
// //u8g2.drawStr(0, 10, "Countdown Timer Menu");
// u8g2.setFont(u8g2_font_freedoomr25_tn);
// u8g2.drawStr(35,63,"00");
// u8g2.drawStr(70,63,":");
// u8g2.drawStr(81,63,"01");
// break;
case MENU_STOPWATCH:
u8g2.drawXBMP( 0, 0, 128, 64, epd_bitmap_New_Project_6_2 );
u8g2.drawXBMP( 28, 55, 9, 6, epd_bitmap_et_select);
u8g2.setFont(u8g2_font_freedoomr25_tn);
//u8g2.drawStr(0, 30, "Stopwatch Menu");
if (stopwatchRunning) {
u8g2.setCursor(40, 63);
u8g2.print((millis() - stopwatchStart) / 1000.0);
} else {
u8g2.setCursor(40, 63);
u8g2.print((stopwatchStop - stopwatchStart) / 1000.0);
}
break;
}
u8g2.sendBuffer(); // transfer internal memory to the display
}