I2C LCD Enno

Transcrição

I2C LCD Enno
LCD-Display 16x2 QAPASS (AllNet)
Ausführliche Beschreibung:
https://arduino-info.wikispaces.com/LCD-Blue-I2C
Library von:
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
Beschreibung der Funktionen findet man in:
https://www.arduino.cc/en/Reference/LiquidCrystal
Achtung: Dieser Code in der Reference funktioniert nicht:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
In den Reference Beispielen sind diese zu ersetzen mit:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)
Wir haben das
I2C LCD DISPLAY VERSION 1.
Der erste Sketch stammt von https://arduino-info.wikispaces.com/LCD-Blue-I2C, den ich
angepasst habe.
Danach eine Tabelle der Funktionen.
Die weiteren Beispiele stammen aus der ursprünglichen LiquidCristal Library, ebenfalls
angepasst.
Die Namen sind leider sinnfrei.
// Angepasst 08.03.2016 Enno Klatt
// Original in https://arduino-info.wikispaces.com/LCD-Blue-I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Setze die LCD-Adresse auf 0x27 für ein 16x2 Display
// Einige nutzen "0x3F"
// Setze die Pins für die Verbindungen des I2C Chip
//
addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
// Serieller Monitor zur Eingabe von Zeichen
// initialisiere das 16x2 Display mit Backlight
// ------- Schnelles Ein- und Ausschalten des Backlight
for(int i = 0; i< 3; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight();
// beenden mit Backlight an
-------------
//-------- Schreibe Zeichen auf das Display -----------------// Beachte: Cursor Position: (Spalte, Zeile) starten mit 0
lcd.setCursor(0,0);
//Beginne in Spalte 0 und Zeile 0
lcd.print("H39 Marienburg!");
delay(1000);
lcd.setCursor(0,1);
lcd.print("Hallo 'DARC'");
// Warten, dann dem Anwender mitteilen, das er den Seriellen Monitor zur
// Eingabe von Zeichen nutzen soll
// Seriellen Monitor auf "kein Zeilenende" einstellen
delay(5000);
lcd.clear();
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print("Nutze Serial Mon");
lcd.setCursor(0,1);
lcd.print("Tippe -> Display");
}
void loop() {
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
Liste der Funktionen
Alle Funktionen nach der Punktnotation nutzen:
„Objekt.Funktion“
z.B.: lcd.clear();
begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
cols[…] die Anzahl Spalten
rows[…] die Anzahl Zeilen
charsize[…] character size, default==LCD_5x8DOTS
Lösccht das LCD und setzt den Cursor in die linke obere Ecke
clear();
Setzt den Cursor in die linke obere Ecke
home();
Schaltet das LCD ab
noDisplay()
Schaltet das LCD an
display()
Schalter das Blinken des Cursors ab
noBlink();
Schalter das Blinken des Cursors an
blink()
Versteckt den Cursor
noCursor();
Zeigt den Cursor an
cursor();
Rollt den Inhalt (Text und Cursor) ein LeerZeichen nach links
scrollDisplayLeft()
Rollt den Inhalt (Text und Cursor) ein LeerZeichen nach rechts
scrollDisplayRight()
Setzt die Schreibrichtung auf dem LCD von links nach rechts
leftToRight()
Setzt die Schreibrichtung auf dem LCD von rechts nach links
rightToLeft()
Bewegt den Cursor ein Leerzeichen nach links
moveCursorLeft()
Bewegt den Cursor ein Leerzeichen nach rechts
moveCursorRight()
Schaltet das automatische rollen des LCD an
Der Effekt ist, das neue Zeichen an der gleichen Position angezeigt
werden
autoscroll()
Schaltet das automatische rollen des LCD aus
noAutoscroll()
Erzeugt einen neues Zeichen zur LCD-Ausgabe
Zeichen von 5x8 Pixel
createChar(uint8_t location, const char *charmap)
Den Cursor positionieren
setCursor(uint8_t col, uint8_t row)
Das LCD Backlight einschalten
backlight()
Das LCD Backlight ausschalten
noBacklight()
Das LCD ausschalten
off()
Das LCD einschalten
on()
Zeichen auf dem LCD ausgeben
write( ... )
print( ... )
// I2C_Autoscroll.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// set the cursor to (15,1):
lcd.setCursor(16, 1);
// set the display to automatically scroll:
lcd.autoscroll();
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// turn off automatic scrolling
lcd.noAutoscroll();
// clear screen for the next loop:
lcd.clear();
}
// I2C_Blink.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hallo Welt!");
}
void loop() {
// Turn off the blinking cursor:
lcd.noBlink();
delay(3000);
// Turn on the blinking cursor:
lcd.blink();
delay(3000);
}
// I2C_Display.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hallo Welt!");
}
void loop() {
// Turn off the display:
lcd.noDisplay();
delay(500);
// Turn on the display:
lcd.display();
delay(500);
}
// I2C_CustomCharacter.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// make some custom characters:
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
byte smiley[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};
byte frownie[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b00000,
0b01110,
0b10001
};
byte armsDown[8] = {
0b00100,
0b01010,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010
};
byte armsUp[8] = {
0b00100,
0b01010,
0b00100,
0b10101,
0b01110,
0b00100,
0b00100,
0b01010
};
void setup() {
// initialize LCD and set up the number of columns and rows:
lcd.begin(16, 2);
// create a new character
lcd.createChar(0, heart);
// create a new character
lcd.createChar(1, smiley);
// create a new character
lcd.createChar(2, frownie);
// create a new character
lcd.createChar(3, armsDown);
// create a new character
lcd.createChar(4, armsUp);
lcd.clear();
// Print a message to the lcd.
lcd.print("I ");
lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a
byte
lcd.print(" Arduino! ");
lcd.write((byte) 1);
}
void loop() {
int delayTime = 250;
// set the cursor to the bottom row, 5th position:
lcd.setCursor(4, 1);
// draw the little man, arms down:
lcd.write(3);
delay(delayTime);
lcd.setCursor(4, 1);
// draw him arms up:
lcd.write(4);
delay(delayTime);
}
// I2C_HelloWorld.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hallo Welt!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
// I2C_Scanner.ino
#include <Wire.h>
void setup() {
Serial.begin (9600);
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++){
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0){
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
// I2C_Scroll.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hallo DARC!");
delay(1000);
}
void loop() {
// scroll 11 positions (string length) to the left
// to move it offscreen left:
for (int positionCounter = 0; positionCounter < 11; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);
}
// scroll 27 positions (string length + display length) to the right
// to move it offscreen right:
for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(150);
}
// scroll 16 positions (display length + string length) to the left
// to move it back to center:
for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);
}
// delay at the end of the full loop:
delay(1000);
}
Ermittelt die Adresse des I2C-Interfaces, meist „0x27“
// I2C_SerialDisplay.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop() {
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
// I2C_TextDirection.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int thisChar = 'a';
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// turn on the cursor:
lcd.cursor();
}
void loop() {
// reverse directions at 'm':
if (thisChar == 'm') {
// go right for the next letter
lcd.rightToLeft();
}
// reverse again at 's':
if (thisChar == 's') {
// go left for the next letter
lcd.leftToRight();
}
// reset at 'z':
if (thisChar > 'z') {
// go to (0,0):
lcd.home();
// start again at 0
thisChar = 'a';
}
// print the character
lcd.write(thisChar);
// wait a second:
delay(1000);
// increment the letter:
thisChar++;
}

Documentos relacionados