#include "U8g2lib.h"
// #include "LetterAnalog.h"
#define SCL_PIN 22
#define SDA_PIN 21
#define BUTTON_UP_PIN 5
#define BUTTON_DOWN_PIN 4
#define BUTTON_SELECT_PIN 15
#define BUTTON_ANALOG 2
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, SCL_PIN, SDA_PIN);
int button_up_clicked = 0;
int button_select_clicked = 0;
int button_down_clicked = 0;
int selected = 0;
String letter_selected = "";
int letter_selected_length=0;
static const int TOTAL_MENU = 27;
const char *options[TOTAL_MENU] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_"};
void setup() {
pinMode(BUTTON_UP_PIN, INPUT_PULLUP);
pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP);
pinMode(BUTTON_SELECT_PIN, INPUT_PULLUP);
u8g2.begin();
Serial.begin(115200);
}
void lett_analog(int an) {
if (an == 0) { //0
selected = 0;
}
else if (an>4077 ){ //
selected = 26;
}
else {
selected = an/151;
}
}
void loop() {
int Val = analogRead(BUTTON_ANALOG);
Serial.println(selected);
lett_analog(Val);
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x13B_tf);
for (int i = 0; i < TOTAL_MENU; i++) {
if (i == selected) {
u8g2.setFontMode(0);
u8g2.setDrawColor(0);
} else if (i != selected) {
u8g2.setFontMode(1);
u8g2.setDrawColor(1);
}
if (i <9) {
int sel = (i*12)+4;
u8g2.setCursor((sel), 36);
}
else if (i >8 && i <18) {
int sel = ((i-9)*12)+4;
u8g2.setCursor((sel), 48);
}
else if (i >17 && i <27) {
int sel = ((i-18)*12)+4;
u8g2.setCursor((sel), 60);
}
u8g2.print(options[i]);
// Serial.println(i);
// u8g2.print(letter_selected);
// Serial.println(sel);
}
if ((digitalRead(BUTTON_SELECT_PIN) == LOW) && (button_select_clicked == 0)) {
for (int l = 0; l < TOTAL_MENU; l++) {
letter_selected=letter_selected + options[l];
Serial.println(letter_selected);
letter_selected_length++;;
}
button_select_clicked = 1;
}
u8g2.setFontMode(1);
u8g2.setDrawColor(1);
u8g2.setCursor(4, 18);
u8g2.sendBuffer();
// start Unclick
if ((digitalRead(BUTTON_UP_PIN) == HIGH) && (button_up_clicked == 1)) {
button_up_clicked = 0;
}
if ((digitalRead(BUTTON_DOWN_PIN) == HIGH) && (button_down_clicked == 1)) {
button_down_clicked = 0;
}
if ((digitalRead(BUTTON_SELECT_PIN) == HIGH) && (button_select_clicked == 1)) {
button_select_clicked = 0;
}
// end Unclick
if ((digitalRead(BUTTON_DOWN_PIN) == LOW) && (button_down_clicked == 0)) {
button_down_clicked = 1;
selected = selected + 1;
// Serial.println(selected);
delay(200);
};
if ((digitalRead(BUTTON_UP_PIN) == LOW) && (button_up_clicked == 0)) {
button_up_clicked = 1;
selected = selected - 1;
// Serial.println(selected);
delay(200);
};
}