Relais mit Taster Schalten und LCD Lauftext

ES FUNNKTIONIERT :heart_eyes: :heart_eyes: :heart_eyes:

#include <LiquidCrystal.h>

unsigned int  Contrast = 75;
LiquidCrystal lcd(41, 42, 43, 40, 45, 46);

const byte contrastPin = 44;

const byte rel = 31;
const byte taster = 30;
byte posCounter = 0;
bool tasterstatus = LOW;
byte richtung = 0;
unsigned long relaisEinZeit = 0;

void setup()
{
  analogWrite(contrastPin, Contrast);
  lcd.begin(16, 2);
  lcd.print("Lauftext Zeile 1");
  lcd.setCursor(0, 1);
  lcd.print("Lauftext Zeile 2");
  pinMode(rel, OUTPUT);
  digitalWrite(rel, LOW);
  pinMode(taster, INPUT_PULLUP);
}


void loop()
{
  anzeige();
  relais();
}

bool tik(const uint32_t startmillis, const uint32_t pause)
{
  if (millis() - startmillis >= pause)
  {
    return true;
  }
  return false;
}

void relais()
{
  if (!digitalRead(taster))             // Taster gedrückt? ...
  {
    if (!digitalRead(rel))             // ... und Relais ist aus? ...
    {
      digitalWrite(rel, HIGH);         // ... relais an ....
      relaisEinZeit = millis();        // ... merke zeit für delay (2000);
    }
  }
  if (digitalRead(rel) && tik(relaisEinZeit, 2000))  // taste ist losgelassen UND Zeit abgelaufen?
  {
    digitalWrite(rel, LOW);            // mache relais aus
  }
}

void anzeige()
{
  static uint32_t myMillis = millis();
  switch (richtung)
  {
    case 0:
      if (posCounter < 14)
      {
        if (tik(myMillis, 400))
        {
          lcd.scrollDisplayLeft();
          posCounter++;
          myMillis = millis();
        }
      }
      else
      {
        richtung = 1;
        posCounter = 0;
        myMillis = millis();
      }
      break;
    case 1:
      if (posCounter < 28)
      {
        if (tik(myMillis, 400))
        {
          lcd.scrollDisplayRight();
          posCounter++;
          myMillis = millis();
        }
      }
      else
      {
        richtung = 2;
        posCounter = 0;
        myMillis = millis();
      }
      break;
    case 2:
      if (posCounter < 14)
      {
        if (tik(myMillis, 400))
        {
          lcd.scrollDisplayLeft();
          posCounter++;
          myMillis = millis();
        }
      }
      else
      {
        richtung = 3;
        posCounter = 0;
        myMillis = millis();
      }
      break;
    case 3:
      if (tik(myMillis, 3000))
      {
        posCounter = 0;
        richtung = 0;
      }
      break;
  }
}

Sehr, sehr, sehr geil @my_xy_projekt !!! Jetzt kann ich mich definitv dran machen das besser zu verstehen und am ende drei Taster und vier Relais zu betreiben :grin:

Daran werde ich mich aber definitiv erstmal selbst versuchen - ich denke das bekomme schon irgendwie hin. Müsste ja grobgesagt mehr oder weniger nur Copy-Paste sein.

Noch mal für mich zum weiteren Verständnis

if (digitalRead(rel))  =  if (digitalRead(rel) == HIGH)

if (!digitalRead(rel)) = if (digitalRead(rel) == LOW)

Kann ich dann jedes HIGH und LOW durch (digitalRead()) oder (!digitalRead()) ersetzen? Funktioniert das auch mit (digitalWrite())?