#include <MobaTools.h>
// Relais Nr 0, 1, 2, 3, 4, 5, 6, 7, 8
const byte relaisPin[] = {254, 2, 3, 4, 10, 11, 7, 8, 9};
// button Nr 0 1, 2, 3, 4, 5, 6, 7, 8
const byte buttonPin[] = {254, 5, 6, 12, A0, A1, A2, A3, A4};
// Relais Nr 0, 1, 2, 3, 4, 5, 6, 7, 8
boolean blinkenAktiv[] = {false, false, false, false, false, false, false, false, false};
byte lastButtonState[9];
// Relais Nr 0, 1, 2, 3, 4, 5, 6, 7, 8
const unsigned long onZeit[] = {0, 400, 400, 400, 400, 400, 400, 400, 0};
// Relais Nr 0, 1, 2, 3, 4, 5, 6, 7, 8
const unsigned long offZeit[] = {0, 5000, 10000, 176600, 209600, 160000, 800, 800, 0};
const byte debounceTime = 50;
const uint16_t pressTime = 1000;
const byte NoOfButtons = 9;
//MoToButtons myButtons( buttonPin, uint8_t debTime, uint16_t pressTime );
MoToButtons myButtons(buttonPin,NoOfButtons,debounceTime,pressTime);
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start");
for (byte IndexNr = 1; IndexNr <= 8; IndexNr++) {
Serial.print("Setze IO-Pin Nr:");
Serial.print(relaisPin[IndexNr]);
Serial.println(" als OUTPUT");
pinMode(relaisPin[IndexNr], OUTPUT);
}
}
void buttonsAbfragenAnAusSchalten() {
for (byte IndexNr = 1; IndexNr <= 8; IndexNr++) {
// prüfe ob ein button gedrückt wurde
if (myButtons.pressed(IndexNr) == true) {
Serial.print("myButtons.pressed(");
Serial.print(IndexNr);
Serial.println(")");
// wenn button gedrückt wurde
// invertiere den Zustand der An-Aus-Variable
blinkenAktiv[IndexNr] = !blinkenAktiv[IndexNr];
Serial.print("blinkenAktiv[");
Serial.print(IndexNr);
Serial.print("]=");
Serial.println(blinkenAktiv[IndexNr]);
}
}
}
void loop() {
myButtons.processButtons(); // muss regelmäßig = ca. 100 mal pro Sekunde aufgerufen werden.
buttonsAbfragenAnAusSchalten();
for (byte IndexNr = 1; IndexNr <= 8; IndexNr++) {
if (blinkenAktiv[IndexNr] == true) {
delay(1);
digitalWrite(relaisPin[IndexNr], (millis() % (onZeit[IndexNr] + offZeit[IndexNr])) < onZeit[IndexNr]);
}
}
}