1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
| #include <avr/wdt.h>
// Declare Pin numbers: //
// OUTPUTS //
int PinD0 = 2;
int PinD1 = 3;
int PinD2 = 4;
int PinD3 = 5;
int PinD4 = 6;
int PinD5 = 7;
int PinD6 = 8;
int PinD7 = 9;
int PinD8 = 10;
int PinD9 = 11;
int PinD10 = 12;
int PinD11 = 13;
int PinD12 = 42;
int PinD13 = 43;
int PinD14 = 44;
int PinD15 = 45;
int PinD16 = 46;
int PinD17 = 47;
int PinD18 = 48;
int PinD19 = 49;
// INPUTS //
int PinA0 = A0;
int PinA1 = A1;
int PinA2 = A2;
int PinA3 = A3;
int PinA4 = A4;
int PinA5 = A5;
int PinA6 = A6;
int PinA7 = A7;
int PinA8 = A8;
int PinA9 = A9;
int PinA10 = A10;
int PinA11 = A11;
int PinA12 = A12;
int PinA13 = A13;
int PinA14 = A14;
int PinA15 = A15;
// Declare Variables //
int LogVariable;
int i, n;
int OutputPin[20] { PinD0, PinD1, PinD2, PinD3, PinD4, PinD5, PinD6, PinD7, PinD8, PinD9, PinD10, PinD11, PinD12, PinD13, PinD14, PinD15, PinD16, PinD17, PinD18, PinD19 };
int InputRead[16];
int OutputRead[20];
int InputPin[16] = { PinA0, PinA1, PinA2, PinA3, PinA4, PinA5, PinA6, PinA7, PinA8, PinA9, PinA10, PinA11, PinA12, PinA13, PinA14, PinA15 };
int InputLastState[16];
int InputButtonState[16];
int ButtonStateValue[16] = { HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH } ;
String LogText, SerialInput;
String InputLogText[16] = { "InputA0 = ", "InputA1 = ", "InputA2 = ", "InputA3 = ", "InputA4 = ","InputA5 = ","InputA6 = ", "InputA7 = ", "InputA8 = ", "InputA9 = ", "InputA10 = ","InputA11 = ", "InputA12 = ", "InputA13 = ", "InputA14 = ", "InputA15 = " };
String OutputLogText[20] = { "OutputD0 = ", "OutputD1 = ", "OutputD2 = ", "OutputD3 = ", "OutputD4 = ","OutputD5 = ","OutputD6 = ", "OutputD7 = ", "OutputD8 = ", "OutputD9 = ", "OutputD10 = ","OutputD11 = ", "OutputD12 = ", "OutputD13 = ", "OutputD14 = ", "OutputD15 = ", "OutputD16 = ", "OutputD17 = ", "OutputD18 = ", "OutputD19 = " };
unsigned long InputDebounceT1[16];
unsigned long WatchdogT2;
void InputA0Function(int i), InputA1Function(int i), InputA2Function(int i), InputA3Function(int i), InputA4Function(int i), InputA5Function(int i), InputA6Function(int i), InputA7Function(int i), InputA8Function(int i), InputA9Function(int i), InputA10Function(int i), InputA11Function(int i), InputA12Function(int i), InputA13Function(int i), InputA14Function(int i), InputA15Function(int i);
int DebounceDelay = 25; // Button Debounce delay (milliseconds)
const long WatchdogInterval = 1000; // Blink Interval (milliseconds)
typedef void (*vvFunction)(int i);
vvFunction VarFunction[16] = { InputA0Function, InputA1Function, InputA2Function, InputA3Function, InputA4Function, InputA5Function, InputA6Function, InputA7Function, InputA8Function, InputA9Function, InputA10Function, InputA11Function, InputA12Function, InputA13Function, InputA14Function, InputA15Function } ;
void setup() {
wdt_enable(WDTO_8S);
Serial.begin(9600);
PinMode();
}
void loop() {
Watchdog();
for (n=0; n<=15; n=n+1){
InputRead[n] = digitalRead(InputPin[n]);
if (InputRead[n] != InputLastState[n]) {
InputDebounceT1[n] = millis();
} else {
InputDebounce(n);
}
InputLastState[n] = InputRead[n];
}
n=0;
}
void InputDebounce(int i){
if (InputRead[i] != InputLastState[i]) {
InputDebounceT1[i] = millis();
} else {
if ((millis() - InputDebounceT1[i]) > DebounceDelay) {
if (InputRead[i] != InputButtonState[i]) {
InputButtonState[i] = InputRead[i];
if (InputButtonState[i] == ButtonStateValue[i]) {
VarFunction[i](i);
Serial.println("");
} else{
if (InputLogText[i].length() > 0){
SerialLog(InputLogText[i], InputRead[i]);
Serial.println("");
}
}
}
}
}
}
void PinMode(){
for (i=0; i<=19; i=i+1){
pinMode(OutputPin[i], OUTPUT);
}
}
void InputA0Function(int i){
InputFunction(i);
}
void InputA1Function(int i){
InputFunction(i);
}
void InputA2Function(int i){
InputFunction(i);
}
void InputA3Function(int i){
InputFunction(i);
}
void InputA4Function(int i){
InputFunction(i);
}
void InputA5Function(int i){
InputFunction(i);
}
void InputA6Function(int i){
InputFunction(i);
}
void InputA7Function(int i){
InputFunction(i);
}
void InputA8Function(int i){
InputFunction(i);
}
void InputA9Function(int i){
InputFunction(i);
}
void InputA10Function(int i){
InputFunction(i);
}
void InputA11Function(int i){
InputFunction(i);
}
void InputA12Function(int i){
InputFunction(i);
}
void InputA13Function(int i){
InputFunction(i);
}
void InputA14Function(int i){
InputFunction(i);
}
void InputA15Function(int i){
InputFunction(i);
}
void InputFunction(int i){
SerialLog(InputLogText[i], InputRead[i]);
digitalWrite(OutputPin[i], !digitalRead(OutputPin[i]));
SerialLog(OutputLogText[i], digitalRead(OutputPin[i]));
}
void SerialLog(String LogText, int LogVariable){
Serial.print(LogText);
Serial.println(LogVariable, DEC);
}
void Watchdog(){
unsigned long WatchdogT1 = millis();
wdt_reset();
if (WatchdogT1 - WatchdogT2 >= WatchdogInterval) {
WatchdogT2 = WatchdogT1;
digitalWrite(PinD16, !digitalRead(PinD16));
}
} |