Mache ich das nächste mal Tommy...
OK. Hier mal des ganze Sketch gehört zwar zu einem anderem Thema, wie gesagt noch nicht ganz fertig.
//**************************************************************
// ********** Blink Signal Übersetzer zur Alarmanlage **********
//**************************************************************
//
// Blinkfolge der "ZONE STATUS" - LED
//
// Alarm: 120 ms Impuls 120 ms Pause |--|__|--|__|--|
// Austrittsverzögerung aktiv Zonen OK (60Sek) 280 ms Impuls 280 ms Pause |----|____|----|____|
// Anlage aktiv: 2 x 120 ms Impuls dann 1750 ms Pause |--|__|--|_________|--|__|--|
// Alarm gespeichert 3 x 120 ms Impuls dann 15000 ms Pause |--|__|--|__|--|_______|--|__|--|__|--|
// Austrittsverzögerung aktiv Schleifen NICHT OK LED leuchtet dauernd |----------------
// Anlage inaktiv LED leuchtet nicht |________________
//
//***************************************************************
//
//
#include <LiquidCrystal.h>
// LCD-Pin Zuordnung ! R/W auf Ground !
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const byte eingang = 7; // Eingangs Pin des Signales (5V/0V)
const uint32_t messIntervall = 2000; // Messintervall 2 Sekunden
uint32_t aktMillis, messMillis;
byte zaehler, aktStatus, altStatus;
bool aktE, altE; // aktuelles Ereignis , altes Ereignis
int HBL = 13; // Hintergrundbeleuchtung
unsigned long anZeit = 5000; // Zeit der Beleuchtung
unsigned long ausZeit = 10000;
unsigned long previousMillis = 0;
unsigned long previousMillisan = 0;
int ledState = LOW;
void setup()
{
pinMode(HBL,OUTPUT);
// **** LCD 16x1 wird wie LCD 8x2 behandelt ****
//
// ###################################
// #|1|_|_|_|_|_|_|_|2|_|_|_|_|_|_|_|#
// ###################################
//
// *********************************************
lcd.begin(8,2); // Display initialisieren 8 Zeichen und 2 Zeilen
// Gibt einen Text auf LCD aus.
lcd.setCursor(0,0); // SetCursor (Spalte,Zeile)
lcd.print("Signalzu");
lcd.setCursor(0,1);
lcd.print("ordnung");
delay (1000);
lcd.clear();
lcd.setCursor(0,0); // SetCursor (Spalte,Zeile)
lcd.print("Start");
lcd.setCursor(0,1);
lcd.print(" ");
Serial.begin(9600);
Serial.println(F("Anfang"));
}
void loop()
{
HGBLaus();
aktMillis = millis();
altE = aktE;
aktE = digitalRead(eingang);
//-------------------------------------------------
if (aktE != altE)
{
zaehler++;
}
//-------------------------------------------------
if (aktMillis - messMillis >= messIntervall)
{
aktStatus = 0;
if (zaehler == 0)
{
//-------------------------------------------------
if (aktE)
{
aktStatus = 6;
} else {
aktStatus = 5;
}
}
//----------------------------------------
if ( zaehler > 20 )
{
aktStatus = 6;
}
else
if ((zaehler >= 16) && ( zaehler < 20 ) )
{
aktStatus = 1;
}
else if ( (zaehler >= 7) && ( zaehler < 20 ) )
{
aktStatus = 2;
}
else if ((zaehler == 4) || (zaehler ==3))
{
aktStatus = 3;
}
else if ( (zaehler >= 5) && ( zaehler < 20 ))
{
aktStatus = 4;
}
if (aktStatus != altStatus)
{
Serial.print(F("Impulse "));
Serial.print(zaehler);
Serial.print(F("\tStatus "));
Serial.println(aktStatus);
//------------------------------------------------
if (aktStatus == 1 )
{
Serial.println ( " A L A R M " );
}
if (aktStatus == 2 )
{
Serial.println ( " AVZ OK " );
}
if (aktStatus == 3 )
{
Serial.println ( " Aktiv " );
lcd.clear();
lcd.setCursor(0,0); // SetCursor (Spalte,Zeile)
lcd.print("Aktiv");
lcd.setCursor(0,1);
lcd.print(" ");
HGBLan();
}
if (aktStatus == 4 )
{
Serial.println ( " Alarm gespeichert " );
}
if (aktStatus == 5 )
{
Serial.println ( " I N A K T I V " );
lcd.clear();
lcd.setCursor(0,0); // SetCursor (Spalte,Zeile)
lcd.print("Inaktiv");
lcd.setCursor(0,1);
lcd.print(" ");
HGBLan();
}
if (aktStatus == 6)
{
Serial.println ( " AVZ nicht OK - Tür offen " );
lcd.clear();
lcd.setCursor(0,0); // SetCursor (Spalte,Zeile)
lcd.print("Tuer off");
lcd.setCursor(0,1);
lcd.print("en ");
HGBLan();
}
if (aktStatus == 0 )
{
Serial.println ( " Fehler ");
}
altStatus = aktStatus;
}
messMillis = aktMillis;
zaehler = 0;
}
}
void HGBLan()
{
unsigned long currentMillisan = millis();
if (currentMillisan - previousMillisan >= anZeit) {
previousMillisan = currentMillisan;
digitalWrite(HBL,HIGH);
}
}
void HGBLaus()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= ausZeit) {
previousMillis = currentMillis;
digitalWrite(HBL,LOW);
}
}