LCD Display Programmieren?

Elumania  15.06.2021, 07:40

Welches Display hast du? Bauteilnummer? 16x2 Display? Falls unbekannt bitte ein Bild posten. Arbeitest du mit TinkerCad oder richtig mit der Hardware?

oio56789 
Fragesteller
 15.06.2021, 10:01

Ja es ist 16x2 der Name ist LiquidCrystal_I2C. Ich arbeite nur mit Arduino und muss ein Sketch mit einem "Würfel" bzw. Zufallssystem schreiben, dabei brauche ich Hilfe.

2 Antworten

Vom Fragesteller als hilfreich ausgezeichnet

Hallo,

ich habe nicht die LiquidCrystal_I2C genommen sondern die LiquidCrystal. Der Unterschied ist, dass man mehr Kabel benötigt. Wie das angeschlossen wird, siehst du im Code.

Ich verwende ein LCD Shield, das auf den Arduino draufgesteckt werden kann. Mein Programm gibt Zufallszahlen in der zweiten Reihe von 1 bis 6 aus, die jede Sekunde aktualisiert wird.

/* The circuit:
 * LCD RS pin to digital pin 8
 * LCD Enable pin to digital pin 9
 * LCD D4 pin to digital pin 4
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 6
 * LCD D7 pin to digital pin 7
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
*/

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// these constants won't change. But you can change the size of your LCD using them:
const int numRows = 2;
const int numCols = 16;

void setup() {
 // set up the LCD's number of columns and rows:
 lcd.begin(numCols, numRows);
}

void loop() {
 int thisCol = 0; //Spalte Cursor LCD-Display
 int thisRow = 0; //Zeile Cursor LCD-Display
 lcd.setCursor(thisCol, thisRow); // set the cursor position:
 lcd.write("Zufallszahl:");
 thisRow = 1;
 lcd.setCursor(thisCol, thisRow); // set the cursor position:

 long zufallszahl = random(1, 6); // Eine Zufallszahl zwischen 1 und 6 ausgeben
 lcd.print(zufallszahl);
 delay(1000);
}

Bibliothek:


Für die Zufallszahlen könntest du z.B. eine Xorshift-PRNG implementieren: https://de.wikipedia.org/wiki/Xorshift

Oder aber du verwendest das "Signal" eine "herumhängenden" Analogpins.

Oder einfach eine Mischung aus beidem.

Für das Display kommt's drauf an, was genau du für eines hast.

P.S.: "LCD-Display" ist wie "PKW-Wagen".

Woher ich das weiß:Hobby