#include "U8g2lib.h"
#include <Wire.h> // library required for IIC communication
#include "RTClib.h" // real time clock module library
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // initialization for the used OLED display
RTC_DS1307 rtc; // initialization for the real time clock module
// ultrasonic
#define trigger 13
#define echo 12
float TotalT= 0 ;
float Speed = 0.000343; // m/us
float Distance =0 ;
//buzzer
#define buzzer 7
//buttons
#define button_1 2
#define button_2 1
#define button_3 4
#define button_4 3
/////////////////////////////////////////////////////////// first page //////////////////////////////////////////////////////////////////////////
// 'itc logo', 16x16px
const unsigned char epd_bitmap_teams_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3c, 0xdc, 0x7b, 0xee, 0x77, 0xee, 0x77,
0xee, 0x77, 0xec, 0x37, 0xd8, 0x1b, 0x9e, 0x79, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'BE logo', 16x16px
const unsigned char epd_bitmap_BE_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x20, 0x04, 0x10, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10, 0x08,
0x20, 0x04, 0xc0, 0x03, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10, 0x00, 0x00
};
// 'teams logo', 16x16px
const unsigned char epd_bitmap_itc_logo [] PROGMEM = {
0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x00, 0x00, 0xfe, 0x1f, 0xfe, 0x3f, 0x30, 0x00, 0xb6, 0x01,
0xb6, 0x01, 0xb6, 0x01, 0xb6, 0x01, 0xb6, 0x01, 0xb6, 0x01, 0xb6, 0x7f, 0xb6, 0x3f, 0x00, 0x00
};
// 'event logo', 16x16px
const unsigned char epd_bitmap_event_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x05, 0x50, 0x05, 0xa8, 0x0a, 0x04, 0x10, 0x54, 0x15,
0x04, 0x10, 0x54, 0x15, 0x04, 0x10, 0x54, 0x15, 0x04, 0x10, 0x04, 0x10, 0xf8, 0x0f, 0x00, 0x00
};
// 'games logo', 16x16px
const unsigned char epd_bitmap_games_logo [] PROGMEM = {
0x00, 0x04, 0x00, 0x02, 0x00, 0x07, 0xf0, 0x0f, 0x08, 0x10, 0x04, 0x20, 0x02, 0x40, 0x12, 0x48,
0x3a, 0x54, 0x12, 0x48, 0x02, 0x40, 0x82, 0x41, 0x44, 0x22, 0x44, 0x22, 0x38, 0x1c, 0x00, 0x00
};
// 'emergence logo', 16x16px
const unsigned char epd_bitmap_emergency_logo [] PROGMEM = {
0x00, 0x00, 0x7c, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x7f, 0x62, 0x41, 0x22, 0x49, 0x12, 0x5d,
0x12, 0x49, 0x22, 0x41, 0x62, 0x7f, 0x42, 0x06, 0x42, 0x02, 0x42, 0x00, 0x7c, 0x00, 0x00, 0x00
};
const unsigned char* bitmap_icons [6] = {
epd_bitmap_itc_logo,
epd_bitmap_BE_logo,
epd_bitmap_teams_logo,
epd_bitmap_event_logo,
epd_bitmap_games_logo,
epd_bitmap_emergency_logo
};
// 'cursor points', 8x64px
const unsigned char epd_bitmap_cursor_points [] PROGMEM = {
0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00,
0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00,
0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00,
0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00
};
// 'selection', 128x21px
const unsigned char epd_bitmap_selection [] PROGMEM = {
0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01,
0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01,
0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
};
/////////////////////////////////////////////////////////////// itc ////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////// BE ///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////// teams ////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////// Games///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////// formation ///////////////////////////////////////////////////////////////////////
int b_up_clicked = 0; // only perform action when button is clicked, and wait until another press
int b_anter_clicked = 0;
int b_down_clicked = 0;
int current_screen = 0;
//screen 1
const int NUM_item = 6;
char menu_items[NUM_item][20]{
{"itc"},
{"BE members"},
{"Teams"},
{"Events"},
{"Games"},
{"Emergency"}
};
int selected =0;
int previous;
int next;
void setup() {
pinMode(button_1, INPUT_PULLUP);
pinMode(button_2, INPUT_PULLUP);
pinMode(button_3, INPUT_PULLUP);
pinMode(button_4, INPUT_PULLUP);
pinMode(buzzer, INPUT);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
u8g2.begin();
u8g2.setBitmapMode(1); // screen mode
}
void loop() {
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
TotalT = pulseIn(echo, HIGH);
Distance = (TotalT * Speed) / 2;
if (Distance <= 1){
u8g2.setFont(u8g_font_7x14);
u8g2.setColorIndex(1);
if(current_screen == 0 || current_screen == 1){
if(digitalRead(button_3) == LOW && (b_up_clicked == 0)){
tone(buzzer, 660, 20);
selected = selected - 1;
b_up_clicked = 1;
if (selected < 0){
selected = NUM_item -1;
}
}
if(digitalRead(button_2) == LOW && (b_down_clicked == 0)){
tone(buzzer, 600, 20);
selected = selected + 1;
b_down_clicked = 1;
if (selected >= NUM_item){
selected = 0;
}
}
if ((digitalRead(button_3) == HIGH) && (b_up_clicked == 1)) { // unclick
b_up_clicked = 0;
}
if ((digitalRead(button_2) == HIGH) && (b_down_clicked == 1)) { // unclick
b_down_clicked = 0;
}
}
previous = selected - 1;
if (previous < 0){previous = NUM_item -1;} //turn to the last
next = selected + 1;
if (next >= NUM_item){next = 0;} //turn to the first
if ((digitalRead(button_1) == LOW) && (b_anter_clicked == 0)) { // select button clicked, jump between screens
tone(buzzer, 523, 60);
tone(buzzer, 659, 40);
tone(buzzer, 900, 40);
b_anter_clicked = 1; // set button to clicked to only perform the action once
if (current_screen == 0) {current_screen = 1;} // menu items screen --> screenshots screen
else if (current_screen == 1 && bitmap_icons[selected] == epd_bitmap_teams_logo) {current_screen = 2;} // screenshots screen --> home with it being formation
else {current_screen = 0 ;} // --> menu items screen
}
if ((digitalRead(button_1) == HIGH) && (b_anter_clicked == 1)) { // unclick
b_anter_clicked = 0;
}
u8g2.firstPage();
do {
if (current_screen == 0) {
u8g2.setFont(u8g_font_7x14);
u8g2.drawStr(25, 15, menu_items[previous]);
u8g2.drawXBMP( 4, 2, 16, 16, bitmap_icons[previous]);
//selected
u8g2.setFont(u8g_font_7x14B);
u8g2.drawStr(25, 37, menu_items[selected]);
u8g2.drawXBMP( 4, 24, 16, 16, bitmap_icons[selected]);
//next
u8g2.setFont(u8g_font_7x14);
u8g2.drawStr(25, 59, menu_items[next]);
u8g2.drawXBMP( 4, 46, 16, 16, bitmap_icons[next]);
u8g2.drawXBMP( 0, 22, 128, 21, epd_bitmap_selection);
u8g2.drawXBMP( 120, 0, 8, 64, epd_bitmap_cursor_points);
u8g2.drawBox(125, 64/6*selected , 8, 64/6); //6 is the number of total items and selected is the number of the selected item
}
else if (current_screen == 1) {
/*
if(bitmap_screenshots[selected] == epd_bitmap_ones_at_the_moment){
u8g2.setFont(u8g_font_7x14);
u8g2.drawStr(3, 21, menu_items_[previous_]);
//selected
u8g2.setFont(u8g_font_7x14B);
u8g2.drawStr(3, 40, menu_items_[selected_]);
//next
u8g2.setFont(u8g_font_7x14);
u8g2.drawStr(3, 58, menu_items_[next_]);
//u8g2.drawBitmapP( 0, 28, 128/8, 16, epd_bitmap_selection_2); //selection
//u8g2.drawBitmapP( 0, 0, 128/8, 9, epd_bitmap_ones_at_the_moment_1);
}
else{
//u8g2.drawBitmapP( 0, 0, 128/8, 64, bitmap_screenshots[selected]); // draw screenshot
u8g2.drawXBMP(0, 0, 128, 64, bitmap_screenshots[selected]);
}
*/
}
}while ( u8g2.nextPage() );
}
else{u8g2.firstPage(); // Start clearing the first page
do {
u8g2.setColorIndex(0); // Set the color index to 0 (clear)
u8g2.drawBox(0, 0, u8g2.getWidth(), u8g2.getHeight()); // Draw a box covering the entire display to clear it
} while (u8g2.nextPage()); // Continue to the next page if available
}
}