// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// ESP32-C3 30pin (C3 SuperMini: 16pin), connected to OLED display, latching pin for LED or 2 language select with one button
//
// Hardware: ESP32-C3 30pin, OLED Display 128x64 I2C,
// External libraries: U8g2lib.h
// Processor selection in Arduino IDE: ESP32 C3 Dev Module
// I2C Hardware: pin8 (SDA) pin 9 (SCL)
// What it does:
// -
// -
// to be added: -
// - -
// -
// 21.02.24 last (start Feb. 2024)
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include <U8g2lib.h> // library for OLED, e.g. 128x64 monochrome
U8G2_SSD1306_128X64_NONAME_F_HW_I2C oled(U8G2_R0); // for WOKWI with hardware I2C pins 8 SDA and 9 SCL
//#define SDA 8 // not Wokwi: SDA pin assigned to any GPIO pin
//#define SCL 9 // not Wokwi: SCL pin assigned to any GPIO pin
//U8G2_SSD1309_128X64_NONAME0_F_SW_I2C oled(U8G2_R0, SCL, SDA, U8X8_PIN_NONE); // not Wokwi for small 0.96" OLED
//U8G2_SSD1309_128X64_NONAME2_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8); // ============GETESTET 2.42"!!! ==============
const int buttonPin = 5;
const int ledPin = 2;
//int buttonState = 0; // starting value, button not pressed
//float cursor = 3.4321; // variable to play with...
int arrayPointer = -1; // starting value for array position ( "0" is first menu item, so "-1" will start with first menu name)
String arrayStation[8] =
{
"Mega Shuffle",
"WayUp Radio",
"Asia Dream",
"KPop Radio",
"Classic FM",
"Lite Favorites",
"MAXXED Out",
"SomaFM Xmas"
};
//const int numCh = sizeof(arrayStation)/sizeof(char *); // ?
String station = arrayStation[arrayPointer];
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // pin set HIGH, goes LOW if pressed
oled.begin(); // begin U8g2lib.h named "oled" for OLED 128x64
oled.clearBuffer(); // clear buffer for storing display content in RAM
//oled.setContrast(200); // brightness of OLED, 0..255
//oled.setDrawColor(1); // ??? set color to white
oled.setFont(u8g2_font_nerhoe_tr); // set font
oled.setCursor(0,10);
oled.print("Switch Station with button"); // oled.print a string instead of oled.drawStr
oled.sendBuffer();
delay(1000);
/*
oled.setFont(u8g2_font_nerhoe_tr); // set font
oled.setFont(u8g2_font_profont11_tr); // set font for small digits
oled.setFont(u8g2_font_profont10_tr); // font for the small label, e.g. "POWER"
*/
}
void loop()
{
//buttonState = digitalRead(buttonPin); // was the button pressed?
if (digitalRead(buttonPin) == LOW) // Button B defined as INPUT_PULLUP, LOW means pressed
{ digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(ledPin, LOW); // turn off LED on (HIGH is the voltage level)
oled.clearBuffer();
arrayPointer = (arrayPointer + 1); // raise arrayPointer (station#) by 1 -> too many characters shown, repeating name!
//arrayPointer = (arrayPointer + 1) % numCh; // raise arrayPointer (station#) by 1 % modulo numCh?
if (arrayPointer > 7) // ... if over 7, then...
{ arrayPointer = 0; } // ... set to 0, restart at top of array
station = arrayStation[arrayPointer]; // station gets next station name
oled.setFont(u8g2_font_nerhoe_tr); // set font
oled.setCursor(0,10);
oled.print("Station:"); // oled.print a string instead of oled.drawStr
oled.setCursor(10,30);
//oled.print(station); // oled.print a string instead of oled.drawStr
oled.print(arrayStation[arrayPointer]); // oled.print a string instead of oled.drawStr
oled.setFont(u8g2_font_profont11_tr); // set font for small digits
oled.setCursor(10,50);
oled.println(arrayPointer); // oled.print a variable
oled.setCursor(30,50);
oled.print(sizeof(arrayStation)); // oled.print a variable
oled.sendBuffer(); // send buffer from RAM to display controller
delay(1000);
}
}