1 | int EingangAnzahl = 2;
|
2 | int Eingang[2] = { 11, 12 };
|
3 | int EingangA[1] = { 6 };
|
4 | bool buttonstate[2];
|
5 | bool lastbuttonstate[2][2];
|
6 | unsigned long lastdebouncetime[2];
|
7 | int debouncedelay = 40;
|
8 | bool DebounceAusgabe[2][2];
|
9 | bool DebounceImpuls[2];
|
10 |
|
11 | bool SteckerKontakt = 0;
|
12 | bool SteckerKontaktImpuls = 0;
|
13 | bool Ausschalter = 0;
|
14 | bool AusschalterImpuls = 0;
|
15 |
|
16 | bool Schritt1 = 1;
|
17 | bool Schritt2 = 0;
|
18 |
|
19 | bool SchrittAbgleich[2] = { 0, 0 };
|
20 |
|
21 | int SSRPin = 2;
|
22 | int LedRotPin = 14;
|
23 | int LedGruenPin = 15;
|
24 |
|
25 | void setup() {
|
26 | // put your setup code here, to run once:
|
27 | pinMode(Eingang[0], INPUT_PULLUP);
|
28 | pinMode(Eingang[1], INPUT_PULLUP);
|
29 | pinMode(SSRPin, OUTPUT);
|
30 | pinMode(LedRotPin, OUTPUT);
|
31 | pinMode(LedGruenPin, OUTPUT);
|
32 | }
|
33 |
|
34 | void loop() {
|
35 | // put your main code here, to run repeatedly:
|
36 | EingangDigital();
|
37 | Debounce();
|
38 | Eingangszuordnung();
|
39 | Ablauf();
|
40 | Ausgang();
|
41 | }
|
42 | void (*resetFunc)(void) = 0;
|
43 | void EingangDigital() {
|
44 | int a = 0;
|
45 | while (a < EingangAnzahl) {
|
46 | bool reading[2];
|
47 | reading[0] = digitalRead(Eingang[a]);
|
48 | if (reading[0] == 0) {
|
49 | reading[1] = 1;
|
50 | } else {
|
51 | reading[1] = 0;
|
52 | }
|
53 | buttonstate[a] = reading[1];
|
54 | a++;
|
55 | }
|
56 | }
|
57 | void Debounce() {
|
58 | int a = 0;
|
59 | while (a < EingangAnzahl) {
|
60 | if (buttonstate[a] != lastbuttonstate[a][1]) {
|
61 | lastdebouncetime[a] = millis();
|
62 | }
|
63 | if ((millis() - lastdebouncetime[a]) >= debouncedelay) {
|
64 | if (buttonstate[a] != lastbuttonstate[a][0]) {
|
65 | lastbuttonstate[a][0] = buttonstate[a];
|
66 | }
|
67 | if (lastbuttonstate[a][0] == 1) {
|
68 | DebounceAusgabe[a][0] = 1;
|
69 | if (DebounceImpuls[a] == 0) {
|
70 | DebounceAusgabe[a][1] = 1;
|
71 | DebounceImpuls[a] = 1;
|
72 | } else {
|
73 | DebounceAusgabe[a][1] = 0;
|
74 | }
|
75 | } else {
|
76 | DebounceAusgabe[a][0] = 0;
|
77 | DebounceAusgabe[a][1] = 0;
|
78 | DebounceImpuls[a] = 0;
|
79 | }
|
80 | }
|
81 | lastbuttonstate[a][1] = buttonstate[a];
|
82 | a++;
|
83 | }
|
84 | }
|
85 | void Eingangszuordnung() {
|
86 | SteckerKontakt = DebounceAusgabe[0][0];
|
87 | SteckerKontaktImpuls = DebounceAusgabe[0][1];
|
88 | Ausschalter = DebounceAusgabe[1][0];
|
89 | AusschalterImpuls = DebounceAusgabe[1][1];
|
90 | }
|
91 | void Ausgang() {
|
92 | if ((Schritt1 == HIGH) && (SchrittAbgleich[0] == LOW)) {
|
93 | digitalWrite(SSRPin, LOW);
|
94 | Serial.println("Aus");
|
95 | }
|
96 | if ((Schritt2 == HIGH) && (SchrittAbgleich[1] == LOW)) {
|
97 | digitalWrite(SSRPin, HIGH);
|
98 | Serial.println("Laden");
|
99 | }
|
100 | //LED Anzeige
|
101 | if (Schritt1 == HIGH) {
|
102 | if (SteckerKontakt == LOW) {
|
103 | digitalWrite(LedRotPin, HIGH);
|
104 | digitalWrite(LedGruenPin, LOW);
|
105 | } else {
|
106 | int a;
|
107 | a = millis() % 2000;
|
108 | if (a >= 1000) {
|
109 | digitalWrite(LedRotPin, HIGH);
|
110 | digitalWrite(LedGruenPin, LOW);
|
111 | } else {
|
112 | digitalWrite(LedRotPin, LOW);
|
113 | digitalWrite(LedGruenPin, HIGH);
|
114 | }
|
115 | }
|
116 | }
|
117 | if (Schritt2 == HIGH) {
|
118 | digitalWrite(LedRotPin, LOW);
|
119 | digitalWrite(LedGruenPin, HIGH);
|
120 | }
|
121 | if (millis() >= 3888000000) {
|
122 | resetFunc();
|
123 | }
|
124 | SchrittAbgleich[0] = Schritt1;
|
125 | SchrittAbgleich[1] = Schritt2;
|
126 | }
|
127 | void Ablauf() {
|
128 | if (SteckerKontaktImpuls == HIGH) {
|
129 | Serial.println("SteckerImpuls");
|
130 | }
|
131 | if (AusschalterImpuls == HIGH) {
|
132 | Serial.println("Ausschalter");
|
133 | }
|
134 | if (Schritt1 == HIGH && SteckerKontaktImpuls == HIGH && Ausschalter == LOW) {
|
135 | Schritt2 = HIGH;
|
136 | Schritt1 = LOW;
|
137 | }
|
138 | if (Schritt2 == HIGH && ((SteckerKontakt == LOW) || (Ausschalter == HIGH))) {
|
139 | Schritt1 = HIGH;
|
140 | Schritt2 = LOW;
|
141 | }
|
142 | }
|