Ich habe jetzt nochmal den gesamten Code eingefügt.
Wie muss ich die Debounce Bibliothek in meinen Code einbinden?
Kannst du mir das beispielhaft einmal in meinem Code zeigen?
# include "OneButton.h"
int TASTER = A1;
// Array für die LEDs
int LED[4] = {LED_D0, LED_D1, LED_D2, LED_D3};
int Relay[4] = {D0 ,D1 ,D2, D3};
OneButton NameTaster(TASTER, true);
// LEDs sind beim Start ausgeschaltet
bool Status = LOW;
int buttonState = 0;
int counter = 0;
int i = 0;
int i_2 = 0;
int buttonStateHIGH = 0;
// EINGÄNGE deklarieren
char xI1 = A0; //Eingang 1 Piezo Wohnzimmer
char xI2 = A1; //Eingang 2 Schalter Abstellraum
char xI3 = A2; //Eingang 3
char xI4 = A3; //Eingang 4
char xI5 = A4; //Eingang 5
char xI6 = A5; //Eingang 6
char xI7 = A6; //Eingang 7
char xI8 = A7; //Eingang 8
bool xI1_Status = LOW; //Tasterstatus auf "0" setzen
bool xI2_Status = LOW; //Tasterstatus auf "0" setzen
bool xI3_Status = LOW; //Tasterstatus auf "0" setzen
bool xI4_Status = LOW; //Tasterstatus auf "0" setzen
// AUSGÄNGE deklarieren
char xD0 = D0; //Lampengruppe 1
char xD1 = D1; //Lampengruppe 2
char xD2 = D2; //Lampengruppe 3
char xD3 = D3; //Lampengruppe 4
void setup()
{
Serial.begin(9600);
pinMode( xI1, INPUT); //Deklarierung Eingang
pinMode( xI2, INPUT);
pinMode( xI3, INPUT);
pinMode( xI4, INPUT);
pinMode(BTN_USER, INPUT);
pinMode(xD0, OUTPUT); //Deklarierung Ausgang
pinMode(xD1, OUTPUT);
pinMode(xD2, OUTPUT);
pinMode(xD3, OUTPUT);
pinMode(LED_D0, OUTPUT); //Deklarierung LED´s Steuerung
pinMode(LED_D1, OUTPUT);
pinMode(LED_D2, OUTPUT);
pinMode(LED_D3, OUTPUT);
// LEDs als OUTPUT setzen
for (int i = 0; i <= 5; i ++)
{
pinMode(LED[i], OUTPUT);
}
for (int i = 0; i <= 5; i ++)
{
pinMode(Relay[i], OUTPUT);
}
}
void loop()
{
buttonState = digitalRead(xI1);
if(buttonState == HIGH)
{
if (counter >= 6)
{counter = 0;}
else
{counter++;}
}
changeLights();
}
void changeLights()
{
static bool lastCounter = 0;
switch(counter)
{
case 0: //*Initiaisieren der LED´s und Ausgänge*
digitalWrite(LED_D0, LOW);
digitalWrite(LED_D1, LOW);
digitalWrite(LED_D2, LOW);
digitalWrite(LED_D3, LOW);
digitalWrite(xD0, LOW);
digitalWrite(xD1, LOW);
digitalWrite(xD2, LOW);
digitalWrite(xD3, LOW);
break;
case 1: //*Wechselblinker*
digitalWrite(LED_D0, HIGH);
digitalWrite(LED_D1, HIGH);
digitalWrite(xD0, HIGH);
digitalWrite(xD1, HIGH);
digitalWrite(LED_D2, LOW);
digitalWrite(LED_D3, LOW);
digitalWrite(xD2, LOW);
digitalWrite(xD3, LOW);
delay(800);
digitalWrite(LED_D0, LOW);
digitalWrite(LED_D1, LOW);
digitalWrite(xD0, LOW);
digitalWrite(xD1, LOW);
digitalWrite(LED_D2, HIGH);
digitalWrite(LED_D3, HIGH);
digitalWrite(xD2, HIGH);
digitalWrite(xD3, HIGH);
delay(800);
break;
case 2: //*Aufbau- Abbaulicht*
digitalWrite(LED_D0, HIGH);
digitalWrite(xD0, HIGH);
delay(800);
digitalWrite(LED_D1, HIGH);
digitalWrite(xD1, HIGH);
delay(800);
digitalWrite(LED_D2, HIGH);
digitalWrite(xD2, HIGH);
delay(800);
digitalWrite(LED_D3, HIGH);
digitalWrite(xD3, HIGH);
delay(800);
digitalWrite(LED_D3, LOW);
digitalWrite(xD3, LOW);
delay(800);
digitalWrite(LED_D2, LOW);
digitalWrite(xD2, LOW);
delay(800);
digitalWrite(LED_D1, LOW);
digitalWrite(xD1, LOW);
delay(800);
digitalWrite(LED_D0, LOW);
digitalWrite(xD0, LOW);
delay(800);
break;
case 3: //*Durchaufendes Licht*
digitalWrite(LED_D0, LOW);
digitalWrite(LED_D1, LOW);
digitalWrite(LED_D2, LOW);
digitalWrite(LED_D3, LOW);
digitalWrite(xD0, LOW);
digitalWrite(xD1, LOW);
digitalWrite(xD2, LOW);
digitalWrite(xD3, LOW);
for (int i_2 = 0 ; i_2 <= 4; i_2 ++) //Hochzählen der Ausgänge
{
// aktuelles Ausgang einschalten
digitalWrite(Relay[i_2], HIGH);
delay(800);
// aktuelle LED i ausschalten
digitalWrite(Relay[i_2], LOW);
}
for (int i_2 = 4; i_2 >= 0; i_2 --) //Runterzählen der Ausgänge
{
// aktuelle LED i einschalten
digitalWrite(Relay[i_2], HIGH);
delay(800);
// aktuelle LED i ausschalten
digitalWrite(Relay[i_2], LOW);
digitalWrite(LED[i], LOW);
}
break;
case 4: //*Komplettes Blinklicht*
digitalWrite(LED_D0, HIGH);
digitalWrite(LED_D1, HIGH);
digitalWrite(LED_D2, HIGH);
digitalWrite(LED_D3, HIGH);
digitalWrite(xD0, HIGH);
digitalWrite(xD1, HIGH);
digitalWrite(xD2, HIGH);
digitalWrite(xD3, HIGH);
delay(500);
digitalWrite(LED_D0, LOW);
digitalWrite(LED_D1, LOW);
digitalWrite(LED_D2, LOW);
digitalWrite(LED_D3, LOW);
digitalWrite(xD0, LOW);
digitalWrite(xD1, LOW);
digitalWrite(xD2, LOW);
digitalWrite(xD3, LOW);
delay(500);
break;
}
}