// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// ESP32-S3 44pin, connected to OLED display, latching pin for LED or 2 language select with one button
//
// Hardware: ESP32-S3 44pin, OLED Display 128x64 I2C,
// External libraries: U8g2lib.h
// Processor selection in Arduino IDE: ESP32S3 Dev Module
// Possible Touch Pins for ESP32S3 with 44 pins: GPIO #: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Possible Output Pins for ESP32S3 with 44 pins: GPIO #: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 46
// 0 1 2 19 20 21 35 36 37 38 39 40 41 42 43 44 45 47 48 48 (or38?): internal RGB LED
// What it does:
// -
// -
// to be added: -
// - -
// -
// 21.01.24 last (start dec. 2023)
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#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
const int buttonPin = 15;
const int ledPin = 5;
//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
{ 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);
}
}
/*
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// ESP32-S3 44pin, connected to OLED display, latching pin for LED or 2 language select with one button
//
// Hardware: ESP32-S3 44pin, OLED Display 128x64 I2C,
// External libraries: U8g2lib.h
// Processor selection in Arduino IDE: ESP32S3 Dev Module
// Possible Touch Pins for ESP32S3 with 44 pins: GPIO #: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Possible Output Pins for ESP32S3 with 44 pins: GPIO #: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 46
// 0 1 2 19 20 21 35 36 37 38 39 40 41 42 43 44 45 47 48 48 (or38?): internal RGB LED
// What it does:
// -
// -
// to be added: -
// - -
// -
// 21.01.24 last (start dec. 2023)
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// **************************************************************************************************
// D E F I N I T I O N S *
// **************************************************************************************************
#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
const int buttonPin = 15;
const int ledPin = 5;
int buttonState = 0; // variable definition with starting value 0
float cursor = 3.4321; // variable to play with...
// **************************************************************************************************
// S E T U P *
// **************************************************************************************************
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.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"
//oled.setDrawColor(1); // ??? set color to white
oled.drawStr(0, 10, "Display test in Setup..."); // write some stuff
oled.drawStr(0, 20, "Font: nerhoe_tr"); // write some stuff
oled.setFont(u8g2_font_profont11_tr); // set font for small digits
oled.drawStr(0, 40, "Font: profont11_tr"); // write some stuff
oled.setFont(u8g2_font_profont10_tr); // font for the small label, e.g. "POWER"
oled.drawStr(0, 50, "Font: profont10_tr"); // write some stuff
oled.setCursor(40,64);
oled.print("Value:"); // oled.print a string instead of oled.drawStr
oled.setCursor(80,64);
oled.print(cursor, 2); // oled.print a variable
oled.sendBuffer(); // send buffer from RAM to display controller
delay(2000);
}
// **************************************************************************************************
// F U N C T I O N S *
// **************************************************************************************************
// **************************************************************************************************
// L O O P *
// **************************************************************************************************
void loop()
{
buttonState = digitalRead(buttonPin); // was the button pressed?
if (buttonState == LOW) // if button pressed (LOW) set ledPin from 0->1 or 1->0
{ digitalWrite(ledPin, !digitalRead(ledPin)); // toggle the LED state
delay(200); // debounce was 150 ms, better in Wokwi with 200, unstable <150
}
if (digitalRead(ledPin) == LOW) // if button pressed (LOW) set buttonState HIGH
{ oled.clearBuffer(); // clear buffer for storing display content in RAM
oled.setFont(u8g2_font_nerhoe_tr); // set font
oled.drawStr(0, 10, "Loop: Deutsch..."); // write some stuff
oled.sendBuffer(); // send buffer from RAM to display controller
}
else
{ oled.clearBuffer(); // clear buffer for storing display content in RAM
oled.setFont(u8g2_font_nerhoe_tr); // set font
oled.drawStr(0, 50, "Loop: English..."); // write some stuff
oled.sendBuffer(); // send buffer from RAM to display controller
}
}
*/