Hallo,
Ich bin Neuling und habe leider bisher kaum Ahnung oder Erfahrung mit Arduino oder dem Programmieren von solchen.
Mein Projekt ist eigentlich recht einfach - dachte ich.
Ich habe eine 16x2 LCD anzeige (kein I2C) auf welcher ein Lauftext zu sehen ist. Zusätzlich möchte ich mit einem Taster ein Relais ansteuern, welches dann eine definierte zeit geschaltet bleiben soll.
Wenn ich das Relais alleine mit dem Taster betreibe, funktioniert es Wunderbar. Hier der Code den ich verwende:
int rel = 31;
int taster = 30;
int tasterstatus = 0;
void setup()
{
pinMode(rel, OUTPUT);
pinMode(taster, INPUT);
}
void loop() {
tasterstatus = digitalRead(taster);
if (tasterstatus == HIGH)
{
digitalWrite(rel, HIGH);
delay (2000);
digitalWrite(rel, LOW);
}
else
{
digitalWrite(rel, LOW);
}
}
Das LCD betreibe ich mit folgendem Code:
#include <LiquidCrystal.h>
int Contrast = 75;
LiquidCrystal lcd(41, 42, 43, 40, 45, 46);
//SETUP SETUP SETUP
void setup() {
analogWrite(44, Contrast);
lcd.begin(16, 2);
lcd.print(" Lauftext");
delay(1000);
lcd.setCursor(0, 1);
lcd.print(" Zeile2");
}
///LOOP LOOP LOOP
void loop() {
//LCD Anzeige
{
for (int positionCounter = 0; positionCounter < 14; positionCounter++) {
lcd.scrollDisplayLeft();
delay(400);
}
for (int positionCounter = 0; positionCounter < 28; positionCounter++) {
lcd.scrollDisplayRight();
delay(400);
}
for (int positionCounter = 0; positionCounter < 14; positionCounter++) {
lcd.scrollDisplayLeft();
delay(400);
}
delay(3000);
}
Beides für sich funktioniert wunderbar. Also dachte ich mir ich könnte die beiden Codes einfach zusammenfügen:
#include <LiquidCrystal.h>
int Contrast = 75;
LiquidCrystal lcd(41, 42, 43, 40, 45, 46);
int rel = 31; //Relais
int taster = 30; //Taster
int tasterstatus = 0;
//SETUP SETUP SETUP
void setup() {
analogWrite(44, Contrast);
lcd.begin(16, 2);
lcd.print(" Lauftext");
delay(1000);
lcd.setCursor(0, 1);
lcd.print(" Zeile2");
pinMode(rel, OUTPUT); //Relais
pinMode(taster, INPUT); //Taster
}
///LOOP LOOP LOOP
void loop() {
//LCD Anzeige
{
for (int positionCounter = 0; positionCounter < 14; positionCounter++) {
lcd.scrollDisplayLeft();
delay(400);
}
for (int positionCounter = 0; positionCounter < 28; positionCounter++) {
lcd.scrollDisplayRight();
delay(400);
}
for (int positionCounter = 0; positionCounter < 14; positionCounter++) {
lcd.scrollDisplayLeft();
delay(400);
}
delay(3000);
}
//Relais Steuerung
{
tasterstatus = digitalRead(taster);
if (tasterstatus == HIGH)
{
digitalWrite(rel, HIGH);
delay (2000);
digitalWrite(rel, LOW);
}
else
{
digitalWrite(rel, LOW);
}
}
}
