Försöker förstå / hantera bl.a. funktioner i Arduino IDE.
Följande program fungerar och skriver ut text / tecken från serieporten till bla. en LCD-display.
(dock fungerar inte åäö - ännu, men det blir en annan tråd .: Hantering av t.ex. åäö på en LCD-display (2x16 - I2C))
Kod: Markera allt
/* Idé hämtad från https://forum.arduino.cc/index.php?topic=396450.0
* Displays text sent over the serial port (e.g. from the Serial Monitor) on an attached LCD.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/* -----( Save åäöÅÄÖ on the LED-display )----- */
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
};
*/
/* -----( Declare Constants )----- */
#define I2C_ADDR 0x27 // Adress till LCD-display
int pos = 0;
int strpos = 0;
char receivedChar;
boolean newData = false;
/* -----( Declare objects )----- */
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
lcd.init(); // initialize the lcd
//-------- 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); //Ö
lcd.backlight(); // turn on backlight.
Serial.begin(9600);
while (!Serial) {} // wait for serial port to connect. Needed for native USB
Serial.println("<Arduino is ready>");
}
// when characters arrive over the serial port...
void loop() {
recvOneChar();
showNewData();
}
void recvOneChar() {
if (Serial.available() > 0) {
receivedChar = Serial.read();
newData = true;
// pos = pos + 1;
pos += 1; // Nästa tecken
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
// receivedChar.replace("å", "\1");
Serial.print(receivedChar);
Serial.print(" pos .: ");
Serial.println(pos);
lcd.setCursor(pos,0);
lcd.print(receivedChar);
newData = false;
}
}
Varför fungerar inte följande idé? .:
Kod: Markera allt
...
defChar(); // Save åäöÅÄÖ on the LED-display
...
...
void defChar() {
/* -----( Save åäöÅÄÖ on the LED-display )----- */
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
};
*/
}