/*
IconMenu.ino
This is an interactive demo and requires "next", "prev" and "select" button.
Minimum height of the display should be 64.
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, [email protected]
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Arduino.h>
#include <U8g2lib.h>
//#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
/*
U8g2lib Example Overview:
Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
*/
// Please UNCOMMENT one of the contructor lines below
// U8g2 Contructor List (Frame Buffer)
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
// Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected
//U8G2_NULL u8g2(U8G2_R0); // null device, a 8x8 pixel display which does nothing
//U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition)
//U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_3W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* reset=*/ 8);
////////// U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_128X64_ALT0_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // same as the NONAME variant, but may solve the "every 2nd line skipped" problem
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE); // ESP32 Thing, pure SW emulated I2C
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
//U8G2_SSD1306_128X64_NONAME_F_6800 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_8080 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
//U8G2_SSD1306_128X64_VCOMH0_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range
//U8G2_SSD1306_128X64_ALT0_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but may solve the "every 2nd line skipped" problem
//U8G2_SSD1306_102X64_EA_OLEDS102_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but may solve the "every 2nd line skipped" problem
//U8G2_SSD1312_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1312_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ 8);
//U8G2_SSD1312_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8);
//U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1106_128X64_VCOMH0_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range
//U8G2_SH1106_128X64_WINSTAR_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but uses updated SH1106 init sequence
//U8G2_SH1106_128X32_VISIONOX_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1106_128X32_VISIONOX_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1106_72X40_WISE_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1107_64X128_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1107_128X128_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1107_128X128_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8);
//U8G2_SH1107_128X80_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8);
//U8G2_SH1107_PIMORONI_128X128_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8);
//U8G2_SH1107_SEEED_128X128_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1107_SEEED_128X128_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1107_SEEED_96X96_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);#
//U8G2_SH1107_HJR_OEL1M0201_96X96_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 2, /* data=*/ 0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1107_TK078F288_80X128_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 15, /* dc=*/ 0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1108_128X160_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1108_160X160_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1122_256X64_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h
//U8G2_SH1122_256X64_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h
//U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED
//U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C
//U8G2_SSD1306_128X32_WINSTAR_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C
//U8G2_SSD1306_64X48_ER_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.66" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered
//U8G2_SSD1306_48X64_WINSTAR_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_64X32_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_64X32_1F_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_96X16_ER_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.69" OLED
//U8G2_SSD1306_72X40_ER_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.42" OLED
//U8G2_SSD1306_96X40_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_96X39_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0); // [full framebuffer, size = 1024 bytes]
// End of constructor list
//////////////////////Define High voltage variables///////////////////
int progress = 0; // progress of the progressbar
int inhv_voltage = 0;
int inhv_current = 1;
int value = 0;
float hv_voltage=0.0;
float hv_current=0.0;
float param_hv_type_voltage = 13.0;
float param_hv_type_current = 18.0;
//////////////////////Define Menu Navigation///////////////////
const int num_items = 3; // number of items in the list and also the number of screenshots and screenshots with QR codes (other screens)
const int num_item_lenght = 20; // maximum characters for the item name
char menu_items [num_items] [num_item_lenght] = { // array with item names
{ "ANASAYFA" },
{ "PARAMETRE" },
{ "AYARLAR" },
};
#define button_select_pin 9 // pin for SELECT button
#define button_next_pin 8 // pin for NEXT button
int button_select_clicked = 0; // same as above
int button_next_clicked = 0; // same as above
int item_selected = 0; // which item in the menu is selected
int current_screen = 0; // 0 = menu, 1 = screenshot, 2 = xx
///////////////////////////////////////////////////////////
void setup() {
u8g2.begin(/* menu_select_pin= */ 5, /* menu_next_pin= */ 4, /* menu_prev_pin= */ 2, /* menu_home_pin= */ 3);
// INPUT_PULLUP means the button is HIGH when not pressed, and LOW when pressed
// since it´s connected between some pin and GND
pinMode(button_select_pin, INPUT); // select button
pinMode(button_next_pin, INPUT); // next button
pinMode(inhv_voltage, INPUT);
pinMode(inhv_current, INPUT);
}
void loop() {
///////////////////////CENTER THE TEXT IN SCREEN////////////////////////////////
// Center the text horizontally and vertically
int textWidth = u8g2.getStrWidth(menu_items[item_selected]);
int centerX = (u8g2.getWidth() - textWidth) / 2;
int textHeight = u8g2.getFontAscent() - u8g2.getFontDescent();
int centerY = (u8g2.getHeight() + textHeight) / 2;
///////////////////////READ ANALOG INPUT ///////////////////////////////
hv_voltage = (analogRead(inhv_voltage)*param_hv_type_voltage)/1024.0; // read the value at analog input and scale
hv_current = (analogRead(inhv_current)*param_hv_type_current)/1024.0;
//////////////////////////////////////BUTTON CONTROLS//////////////////////////////
if (digitalRead(button_next_pin) == HIGH) {
if (button_next_clicked == 0) {
item_selected = (item_selected + 1) % num_items;
button_next_clicked = 1;
}
} else if (digitalRead(button_next_pin) == LOW) {
button_next_clicked = 0;
}
////////////////////////////////////////////BACKGROUND/////////////////////////////////////////////
u8g2.drawBox(18, 5, 127, 2);//draw the progress bar fill
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.drawStr(1, 7, "MGM");
u8g2.sendBuffer();
/* increase the progress value to go over 0-100
progress = progress + 1;
if (progress > 109) { //127
progress = 0;
}*/
/////////////////////////////////////////////MAIN PAGE////////////////////////////////////////////////////////////////
if ((digitalRead(button_select_pin)) && (button_select_clicked == 0)) {
button_select_clicked = 1;
if (item_selected == 0) {
current_screen = (current_screen == 0) ? 1 : ((current_screen == 1) ? 2 : 0);
} else if (item_selected == 1) {
current_screen = (current_screen == 0) ? 5 : ((current_screen == 5) ? 6 : 0);
} else if (item_selected == 2) {
current_screen = (current_screen == 0) ? 10 : ((current_screen == 10) ? 11 : 0);
}
}
else if ((digitalRead(button_select_pin) == LOW) && (button_select_clicked == 1)) { // unclick
button_select_clicked = 0;
}
////////////////////////////////WRITE MAIN SCREEN//////////////////////////////
if (current_screen == 0) { // MENU SCREEN
u8g2.clearBuffer(); // required for page drawing mode for u8g2 library
u8g2.setFont(u8g2_font_profont22_tr); // primary font
u8g2.drawStr(centerX, centerY, menu_items[item_selected]);
u8g2.sendBuffer();
}
////////////////////////////SUB SCREEN 1 ///////////////////////////////////////////////
else if (current_screen == 1) {
u8g2.clearBuffer();
static const unsigned char image_Voltage_16x16_bits[] U8X8_PROGMEM = {0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0xc0,0x01,0xe0,0x00,0xf0,0x07,0x80,0x03,0xc0,0x01,0xc0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
u8g2.setBitmapMode(1);
u8g2.setFontMode(1);
u8g2.drawRFrame(55, 18, 71, 21,8);
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 36, "VOLT");
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "AKIM");
u8g2.drawRFrame(55, 42, 71, 21,8);
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.drawStr(111, 60, "mA");
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.drawStr(111, 36, "kV");
u8g2.drawXBMP( 0, 0, 16, 16, image_Voltage_16x16_bits);
u8g2.setFont(u8g2_font_5x8_tr);
u8g2.drawStr(112, 8, "MGM");
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.drawStr(22, 11, "Filtre Aktif");
u8g2.drawLine(127, 14, 0, 14);
//write the HV voltage values to screen
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.setCursor(63, 35);
u8g2.print(hv_voltage,1);
//write the HV current values to screen
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.setCursor(63, 60);
u8g2.print(hv_current,1);
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 2 /////////////////////////////////////////
else if (current_screen == 2) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 2");
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 3 /////////////////////////////////////////
else if (current_screen == 3) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 3");
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 4 /////////////////////////////////////////
else if (current_screen == 4) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 4");
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 5 PARAMETRE /////////////////////////////////////////
else if (current_screen == 5) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 5");
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 6 PARAMETRE /////////////////////////////////////////
else if (current_screen == 6) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 6");
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 7 /////////////////////////////////////////
else if (current_screen == 7) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 7");
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 10 AYARLAR/////////////////////////////////////////
else if (current_screen == 10) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 10");
u8g2.sendBuffer();
}
//////////////////////////////////SUB SCREEN 11 AYARLAR /////////////////////////////////////////
else if (current_screen == 11) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(2, 60, "screen 11");
u8g2.sendBuffer();
}
}