Hier ist mein Code ich verstehe nicht warum die Arduino IDE an meinem Code Rummeckert, kann mir da jemand bitte helfen ?
#include <LiquidCrystal_I2C.h>
int Stumm = 8;
int Test = 9;
int LedRu = 11;
int LedStumm = 13;
int LedTest = 12;
int PipR = 2; //Relai switch strom
int Pip = 3; //RElai eingangs Strom
int AG = 7;
int AO = 6;
int AR = 5;
int AlarmR = 4;
int StrommR = 23;
constexpr byte rows = 2;
constexpr byte cols = 16;
LiquidCrystal_I2C lcd (0x27, cols, rows);
constexpr byte upPin = 22;
constexpr byte downPin = 10;
struct Input {
const byte pin;
const char text[cols + 1];
byte order; // ob und als wie vielte Taste der Pin gedrückt wurde
};
Input input[] {
{ 30, "20/4 Manuel.", 0}, // pin, text, 0
{ 31, "20/7 Auto.", 0},
{ 32, "21/4 Manuel.", 0},
{ 33, "21/8 Auto.", 0},
{ 34, "21/9 Manuel.", 0},
{ 35, "20/4 Auto.", 0},
{ 36, "20/4 Manuel.", 0},
{ 37, "20/4 Auto.", 0},
{ 38, "20/4 Manuel.", 0},
{ 39, "20/4 Auto.", 0},
{ 40, "20/4 Manuel.", 0},
{ 41, "20/4 Auto.", 0},
{ 42, "20/4 Manuel.", 0},
{ 43, "20/4 Auto.", 0},
{ 44, "20/4 Manuel.", 0},
{ 45, "20/4 Auto.", 0},
{ 46, "20/4 Manuel.", 0},
{ 47, "20/4 Auto.", 0},
{ 48, "20/4 Manuel.", 0},
{ 49, "20/4 Auto.", 0},
{ 50, "20/4 Manuel.", 0},
};
constexpr size_t noOfInput = sizeof(input) / sizeof(input[0]);
byte counter;
byte lcdStartLine;
// Suche den nten Eintrag und gib den Index retour
int findEntry(int needle)
{
for (int i = 0; i < noOfInput; i++)
{
if (input[i].order == needle) return i;
}
return - 1; // not found
}
// nur Ausgabe der gespeicherten Reihenfolge
void debug()
{
Serial.println(F("unsortiert"));
for (int i = 0; i < noOfInput; i++)
{
Serial.print(input[i].text); Serial.print(" "); Serial.println(input[i].order);
}
}
// Ausgabe am LCD
void lcdUpdate()
{
debug();
lcd.clear();
int actual = -1;
if (counter > 0)
{
actual = findEntry(lcdStartLine);
Serial.println(actual);
}
if (actual >= 0)
{
Serial.println(input[actual].text);
lcd.print(input[actual].order);
lcd.print(" ");
lcd.print(input[actual].text);
}
lcd.setCursor(0,1);
lcd.print(counter);
lcd.print(F("x Ausgeloest"));
}
void setup() {
pinMode(Stumm, INPUT);
pinMode(Test, INPUT);
pinMode(LedRu, OUTPUT);
pinMode(LedTest, OUTPUT);
pinMode(LedStumm, OUTPUT);
pinMode(PipR, OUTPUT);
pinMode(Pip, OUTPUT);
pinMode(AG, OUTPUT);
pinMode(AO, OUTPUT);
pinMode(AR, OUTPUT);
pinMode(AlarmR, OUTPUT);
pinMode(StrommR, OUTPUT);
Serial.begin(115200);
lcd.init(); // LCD intialisieren
lcd.backlight();
lcd.print(F(" BMZ ist Aktiv"));
lcd.setCursor(0,1);
lcd.print(F("# Keine Alarme #"));
pinMode(upPin, INPUT_PULLUP);
pinMode(downPin, INPUT_PULLUP);
for (auto & i : input) pinMode(i.pin, INPUT_PULLUP);
digitalWrite(PipR, LOW);
digitalWrite(AG, HIGH);
digitalWrite(StrommR, HIGH);
digitalWrite(AlarmR, LOW);
}
void loop() {
for (auto & i : input)
{
if (digitalRead(i.pin) == LOW && i.order == 0)
{
counter++;
i.order = counter;
Serial.print(F("Ausgeloest")); Serial.println(i.text);
lcdStartLine = counter;
lcdUpdate();
if (counter >= noOfInput)
{
Serial.print(F("alle wurden Ausgelöst "));
lcd.setCursor(0, 1);
lcd.print(F("alle Ausgeloest"));
}
}
}
if (digitalRead(upPin) == LOW)
{
if (lcdStartLine > 1) lcdStartLine--;
Serial.print(F("lcdStartLine=")); Serial.println(lcdStartLine);
lcdUpdate();
delay(500); // dirty delay
}
if (digitalRead(downPin) == LOW)
{
if (lcdStartLine < counter) lcdStartLine++;
Serial.print(F("lcdStartLine=")); Serial.println(lcdStartLine);
lcdUpdate();
delay(500); // dirty delay
}
//T Flip FLop Stumm
if (digitalRead(Stumm) == HIGH && digitalRead(LedStumm) == LOW
{
digitalWrite(PipR, HIGH);
//Relai
digitalWrite(AlarmR, LOW);
digitalWrite(LedStumm, HIGH);
delay(3000);
digitalWrite(LedRu, HIGH);
}
else
{
digitalWrite(PipR, LOW);
//Relai
digitalWrite(AlarmR, HIGH);
digitalWrite(LedStumm, LOW);
delay(3000);
digitalWrite(LedRu, LOW);
}
if (digitalRead(Stumm) == HIGH && digitalRead(LedStumm) == HIGH
{
digitalWrite(PipR, LOW);
//Relai
digitalWrite(AlarmR, HIGH);
digitalWrite(LedStumm, LOW);
delay(3000);
digitalWrite(LedRu, LOW);
}
//If Test Knopf
if (digitalRead(Test) == HIGH)
{
digitalWrite(LedTest, HIGH);
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AO, HIGH);
delay(15000); //15 sec
digitalWrite(Pip, LOW);
digitalWrite(AlarmR, LOW);
delay(500);
digitalWrite(LedTest, LOW);
delay(5000);
digitalWrite(AO, LOW);
}
else {
digitalWrite(Pip, LOW);
digitalWrite(LedTest, LOW);
digitalWrite(AO, LOW);
}
if (digitalRead(30) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(31) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(32) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(33) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(34) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(35) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(36) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(37) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(38) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(39) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(40) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(41) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(42) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(43) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(44) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(45) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(46) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(47) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(48) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(49) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
if (digitalRead(50) == HIGH)
{
digitalWrite(AlarmR, HIGH);
digitalWrite(Pip, HIGH);
digitalWrite(AR, HIGH);
}
}