Försöker skriva en sträng (å - Bra gjort!) till en LCD I2C display med en Arduino.
(Men misslyckades!)
Skapade först ett program som skriver ut de svenska tecknen .: åäöÅÄÖ till LCD -displayen.
(Kanske går att lösa på ett smidigare sätt?)
Kod: Markera allt
/*
https://forum.arduino.cc/index.php?topic=224615.0
YourDuino.com Example Software Sketch
16 character 2 line I2C Display
Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"
terry@yourduino.com */
/*-----( Import needed libraries )-----*/
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
/* -----( Declare Constants )----- */
/* -----( Declare objects )----- */
// set the LCD address to 0x27 for a 16 chars 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte AwithRing[8] = {
B00100,
B01010,
B01110,
B00001,
B01111,
B10001,
B01111,
};
byte AwithDots[8] = {
B01010,
B00000,
B01110,
B00001,
B01111,
B10001,
B01111,
};
byte OwithDots[8] = {
B01010,
B00000,
B01110,
B10001,
B10001,
B10001,
B01110,
};
byte BigAwithRing[8] = {
0b00100,
0b01010,
0b01110,
0b10001,
0b11111,
0b10001,
0b10001,
0b00000
};
byte BigAwithDots[8] = {
0b01010,
0b00000,
0b01110,
0b10001,
0b11111,
0b10001,
0b10001,
0b00000
};
byte BigOwithDots[8] = {
0b01010,
0b01110,
0b10001,
0b10001,
0b10001,
0b10001,
0b01110,
0b00000
};
/*
byte Minus[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b00000,
0b00000,
0b00000
};
*/
/*----( SETUP: RUNS ONCE )----*/
void setup() {
Serial.begin(115200); // Used to type in characters
lcd.init();
lcd.backlight();
//-------- Write characters on the display ------------------
lcd.createChar(1, AwithRing); //å
lcd.createChar(2, AwithDots); //ä
lcd.createChar(3, OwithDots); //ö
lcd.createChar(4, BigAwithRing); //Å
lcd.createChar(5, BigAwithDots); //Ä
lcd.createChar(6, BigOwithDots); //Ö
// Display. (Set Serial Monitor option to "No Line Ending")
lcd.clear();
lcd.setCursor(0,0);
lcd.print("å ä ö Å Ä Ö");
lcd.setCursor(0,1);
String message = "\01 \02 \03 \04 \05 \06 ";
lcd.print(message);
} /*--(end setup )---*/
void loop() { /*----( LOOP: RUNS CONSTANTLY )----*/
}
På första raden skrivs ASCII-tecknen ut för å ä ö Å Ä Ö (med Arduinos kod-tabell - liknar japanska )
På andra raden skrivs å ä ö Å Ä Ö ut. (som förväntat.)
Skapade ett nytt program där strängen skrivs ut till LCD-skärmen från en variabel.
Problemet uppstår när å i strängen skall bytas mot den skapade bokstaven å.
Här kommer detta försök till program .:
Kod: Markera allt
/* I2C LCD with Arduino example code. More info: https://www.makerguides.com
https://www.makerguides.com/character-i2c-lcd-arduino-tutorial/ */
// Include the libraries:
// LiquidCrystal_I2C.h: https://github.com/johnrickman/LiquidCrystal_I2C
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
// LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
byte AwithRing[8] = { //å
B00100,
B01010,
B01110,
B00001,
B01111,
B10001,
B01111,
};
byte AwithDots[8] = { //ä
B01010,
B00000,
B01110,
B00001,
B01111,
B10001,
B01111,
};
byte OwithDots[8] = { //ö
B01010,
B00000,
B01110,
B10001,
B10001,
B10001,
B01110,
};
byte BigAwithRing[8] = { //Å
0b00100,
0b01010,
0b01110,
0b10001,
0b11111,
0b10001,
0b10001,
0b00000
};
byte BigAwithDots[8] = { //Ä
0b01010,
0b00000,
0b01110,
0b10001,
0b11111,
0b10001,
0b10001,
0b00000
};
byte BigOwithDots[8] = { //Ö
0b01010,
0b01110,
0b10001,
0b10001,
0b10001,
0b10001,
0b01110,
0b00000
};
// https://www.arduino.cc/en/Reference/VariableDeclaration
// https://www.arduino.cc/reference/en/language/variables/data-types/string/
char TextLCD[16] = "å - Bra gjort!"; // Variable type .: String
int i = 0;
void setup() {
lcd.init(); // Initiate the LCD:
lcd.backlight(); // Backlight ON:
lcd.createChar(1, AwithRing); //å
lcd.createChar(2, AwithDots); //ä
lcd.createChar(3, OwithDots); //ö
lcd.createChar(4, BigAwithRing); //Å
lcd.createChar(5, BigAwithDots); //Ä
lcd.createChar(6, BigOwithDots); //Ö
}
void loop() {
i = 0;
while (i < strlen(TextLCD))
{ lcd.setCursor(i, 0); // Pekare på .: Kolumn1 - Rad1
char pointer = TextLCD[i++];
if ( pointer = "å" ) {
String replace(pointer, "/1");
}
lcd.print(pointer);
// Serial.println(pointer);
delay(500);
}
lcd.clear();
// lcd.setCursor(0, 1); // Pekare på .: Kolumn1 - Rad2
// StringChar.TextLCD(1);
// lcd.print(myChar);
// lcd.print("Hello World!"); // Print the string "Hello World!" - Fungerarar!
// lcd.setCursor(2, 1); //Set the cursor on the third column and the second row (counting starts at 0!).
// lcd.print("LCD tutorial");
}