/*
Buttons 1 4
2 2
3 15
OLED SCL 22
SDA 21
*/
#include <U8g2lib.h>
#include <Bounce2.h>
byte button_pins[] = {4, 2, 15}; // button pins, 4,2 = up/down, 15 = select
#define NUMBUTTONS sizeof(button_pins)
Bounce * buttons = new Bounce[NUMBUTTONS];
U8G2_SSD1306_128X64_NONAME_F_HW_I2C display(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);
//Menü Einstellungen
#define MENU_SIZE 3
#define MENUS_SIZE 5
char *menu[MENU_SIZE] = { "Label Länge", "Stempel", "Clear Prefs" };
int cursor=0;
//Variablen
volatile long temp;
char ausgabe[30]; // Fontsize 12 = 13 Zeichen maximal in einer Zeile
boolean useStamp = false; // Stempel Ja/nein
unsigned int stampPark = 100; // Stempel Ruheposition
unsigned int stampActive = 120; // Stempel aktive Position
void setup() {
Serial.begin(9600);
// Make input & enable pull-up resistors on switch pins
for (int i=0; i<NUMBUTTONS; i++) {
buttons[i].attach( button_pins[i], INPUT_PULLUP); // setup the bounce instance for the current button
buttons[i].interval(25); // interval in ms
}
display.begin();
display.enableUTF8Print();
display.clearBuffer();
display.setCursor(23,45);
display.setFont(u8g2_font_courB10_tf);
display.println("Start");
display.sendBuffer();
delay(2000);
showStartMenu();
}
void loop() {
/*
if ( Position != temp ) { //test für encoder
temp = Position;
Serial.print ("Rotary-Pos: ");
Serial.println (Position);
}
*/
processSettingMenu();
}
void processSettingMenu()
{
// process button press:
for (int i = 0; i<NUMBUTTONS; i++)
{
buttons[i].update(); // Update the Bounce instance
if ( buttons[i].fell() ) // If it fell
{
if (i==2) { // select
executeChoice(cursor);
}
else {
display.clearBuffer();
if (i==0) { // up
cursor++;
if (cursor>(MENU_SIZE-1)) cursor=0;
}
else { // down
cursor--;
if (cursor<0) cursor=(MENU_SIZE-1);
}
// display menu
display.drawFrame(3, 3, 120, 16);
display.setCursor(14,10);
display.setFont(u8g2_font_courB10_tf);
display.println("Einstellungen");
for (int i = 0; i<MENU_SIZE; i++) {
display.setCursor(10,30 + (((i)) * 13));
display.setFont(u8g2_font_courB10_tf);
display.print(menu[i]);
}
// show cursor at new line:
display.setCursor(0,30 + (((cursor)) * 13));
display.setFont(u8g2_font_courB10_tf);
display.print('>');
display.sendBuffer();
}
} // end if button fell...
} // end for-loop of button check
}
//
// Clear display and show the menu.
//
void showStartMenu() {
cursor=0;
display.clearBuffer();
display.drawFrame(3, 3, 120, 16);
display.setCursor(34,14);
display.setFont(u8g2_font_courB10_tf);
display.println("Einstellungen");
// show menu items:
for (int i = 0; i<MENU_SIZE; i++) {
//display.drawString(2,i,menu[i]);
display.setCursor(10,30 + (((i)) * 13));
display.setFont(u8g2_font_courB10_tf);
display.print(menu[i]);
}
display.setCursor(0,30);
display.print('>');
display.sendBuffer();
}
//
//Execute the tasks
//
void executeChoice(int choice) {
switch(choice) {
case 0 :
Serial.println(menu[choice]);
break;
case 1 :
Serial.println(menu[choice]);
break;
case 2 :
Serial.println(menu[choice]);
break;
}
}