Das Problem ist, dass du ein Display-Objekt ansprichst, dass der Kompiler anfangs noch nicht kennt.
Wenn du Auslagern willst, könnte das so gehen:
Vorher:
Code:
// test.ino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(32, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);
void setup()
{
...
createCustomChar();
...
}
...
void createCustomChar()
{
uint8_t bell[8] = {0x04,0x0E,0x0E,0x0E,0x1F,0x00,0x04};
lcd.createChar(0, bell);
}
Nachher:
Code:
// test1.ino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(32, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);
void setup()
{
...
createCustomChar(lcd);
...
}
...
Code:
//test2.ino
#include <LiquidCrystal_I2C.h>
void createCustomChar(LiquidCrystal_I2C lcd)
{
uint8_t bell[8] = {0x04,0x0E,0x0E,0x0E,0x1F,0x00,0x04};
lcd.createChar(0, bell);
}
Ich hoffe das Beispiel ist verständlich. Vorher mit integrierter void-Funktion, nachher ausgelagert. Das Display-Objekt (lcd) wird übergeben, damit es dem Kompiler zur Kompilierzeit bekannt ist.
ODER:
Code:
// test3.ino
void setup()
{
...
createCustomChar();
...
}
...
Code:
//test4.ino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(32, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);
void createCustomChar()
{
uint8_t bell[8] = {0x04,0x0E,0x0E,0x0E,0x1F,0x00,0x04};
lcd.createChar(0, bell);
}
Hierbei ist der Trick, dass die Dateien test3.ino und test4.ino im Ordner test4 liegen. Dadurch erkennt die Arduino-IDE welche Datei als erstes zu interpretieren ist.
ODER:
Code:
// test5.ino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(32, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);
void setup()
{
...
createCustomChar();
...
}
...
Code:
//test6.ino
void createCustomChar()
{
uint8_t bell[8] = {0x04,0x0E,0x0E,0x0E,0x1F,0x00,0x04};
lcd.createChar(0, bell);
}
Hier müssen die Dateien test5.ino und test6.ino im Ordner test5 liegen, damit es funktioniert.
Lesezeichen