Ich habe jetzt hier nur ein 4x20 LCD mit I2C-Backpack zum testen.
Du musst also ggf. die Ansteuerung für das LCD ändern, aber ansonsten sollte das so gehen:
#include <LiquidCrystal_I2C.h> // von https://github.com/marcoschwartz/LiquidCrystal_I2C
LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C-Adresse, Spalten, Zeilen
uint8_t bar[][8] = {
{B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000},
{B01000, B01000, B01000, B01000, B01000, B01000, B01000, B01000},
{B00100, B00100, B00100, B00100, B00100, B00100, B00100, B00100},
{B00010, B00010, B00010, B00010, B00010, B00010, B00010, B00010},
{B00001, B00001, B00001, B00001, B00001, B00001, B00001, B00001}
};
uint8_t ae[8] = {B01010, B00000, B01110, B00001, B01111, B10001, B01111, B00000};
uint8_t volume = 34; // Wert von 0...99
void setVolume(uint8_t vol, uint8_t row) {
if (vol > 99) return;
lcd.setCursor(vol / 5, row);
lcd.write(vol % 5);
}
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
for (byte i = 0; i < 5; i++) {
lcd.createChar(i, bar[i]);
}
lcd.createChar(5, ae);
lcd.setCursor(0, 0);
lcd.print(F("Lautst"));
lcd.write(5);
lcd.print(F("rke"));
setVolume(volume, 1);
}
void loop() {
// put your main code here, to run repeated
}