Also Dein Code funktioniert so bei mir nicht! Ich hab hier meinen gepostet:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int LCD_NB_ROWS = 4 ;
const int LCD_NB_COLUMNS = 20 ;
LiquidCrystal_I2C lcd(0x27, 20,4);
byte START_DIV_0_OF_1 [ 8 ] = {
B01111 ,
B11000 ,
B10000 ,
B10000 ,
B10000 ,
B10000 ,
B11000 ,
B01111
}; // Char start 0/1
byte START_DIV_1_OF_1 [ 8 ] = {
B01111 ,
B11000 ,
B10011 ,
B10111 ,
B10111 ,
B10011 ,
B11000 ,
B01111
}; // Tank beginning 1/1
byte DIV_0_OF_2 [ 8 ] = {
B11111 ,
B00000 ,
B00000 ,
B00000 ,
B00000 ,
B00000 ,
B00000 ,
B11111
}; // Medium tank 0/2
byte DIV_1_OF_2 [ 8 ] = {
B11111 ,
B00000 ,
B11000 ,
B11000 ,
B11000 ,
B11000 ,
B00000 ,
B11111
}; // Medium tank 1/2
byte DIV_2_OF_2 [ 8 ] = {
B11111 ,
B00000 ,
B11011 ,
B11011 ,
B11011 ,
B11011 ,
B00000 ,
B11111
}; // Medium tank 2/2
byte END_DIV_0_OF_1 [ 8 ] = {
B11110 ,
B00011 ,
B00001 ,
B00001 ,
B00001 ,
B00001 ,
B00011 ,
B11110
}; // late tank 0/1
byte END_DIV_1_OF_1 [ 8 ] = {
B11110 ,
B00011 ,
B11001 ,
B11101 ,
B11101 ,
B11001 ,
B00011 ,
B11110
}; // Char end 1/1
void setup_progressbar() {
lcd.createChar(0, START_DIV_0_OF_1);
lcd.createChar(1, START_DIV_1_OF_1);
lcd.createChar(2, DIV_0_OF_2);
lcd.createChar(3, DIV_1_OF_2);
lcd.createChar(4, DIV_2_OF_2);
lcd.createChar(5, END_DIV_0_OF_1);
lcd.createChar(6, END_DIV_1_OF_1);
}
void draw_progressbar(byte lcdwert) {
lcd.setCursor(0, 0);
lcd.print(lcdwert);
lcd.print(" % ");
lcd.setCursor(0, 1);
// byte nb_columns = map(lcdwert, 0, 100, 0, LCD_NB_COLUMNS * 2 - 2);
byte nb_columns = map(lcdwert, 0, 100, 0, LCD_NB_COLUMNS * 2 - 2);
// Chaque caractére affiche 2 barres verticales, mais le premier et dernier caractére n'en affiche qu'une.
for (byte i = 0; i < LCD_NB_COLUMNS; ++i) {
if (i == 0) { // Premiére case
if (nb_columns > 0) {
lcd.write(1); // Char début 1 / 1
nb_columns -= 1;
} else {
lcd.write((byte) 0); // Char début 0 / 1
}
} else if (i == LCD_NB_COLUMNS -1) { // Derniére case
if (nb_columns > 0) {
lcd.write(6); // Char fin 1 / 1
} else {
lcd.write(5); // Char fin 0 / 1
}
} else { // Autres cases
if (nb_columns >= 2) {
lcd.write(4); // Char div 2 / 2
nb_columns -= 2;
} else if (nb_columns == 1) {
lcd.write(3); // Char div 1 / 2
nb_columns -= 1;
} else {
lcd.write(2); // Char div 0 / 2
}
}
}
}
void setup(){
lcd.begin(20, 4);
lcd.init();
lcd.backlight();
setup_progressbar();
lcd.clear();
}
void loop(){
for (uint16_t zahl = 0; zahl <= 800; zahl += 10)
{
byte lcdwert = zahl / 8;
draw_progressbar(lcdwert);
lcd.setCursor(0, 2);
lcd.print("Wert: ");
lcd.print(zahl);
lcd.print(" ");
delay(100);
}
delay(2000);
}
Der Grobe unterschied:
LiquidCrystal_I2C lcd(0x27, 20,4); // I2C Adresse, Felder, Zeilen
/* im Setup */
//lcd.begin(20, 4); // <- Das brauche ich nicht unbediengt
lcd.init(); // <- ohne dem geht gar nichts!
lcd.backlight();
lg dony
edit: Ich verwende ein 20x4 Display, mit einem IC: PCF8574T von YUR BOT ist das 'breakout' hinten am Display.