Browse Source

properly switch relais gpios high when inactive.

Thomas Buck 3 years ago
parent
commit
30aa0a8a35
1 changed files with 12 additions and 2 deletions
  1. 12
    2
      src/GPIOBank.cpp

+ 12
- 2
src/GPIOBank.cpp View File

6
 #include "WifiStuff.h"
6
 #include "WifiStuff.h"
7
 #endif // PLATFORM_ESP
7
 #endif // PLATFORM_ESP
8
 
8
 
9
+//#define GPIO_HIGH_AS_INPUT
10
+
9
 GPIOBank::GPIOBank(int _size) {
11
 GPIOBank::GPIOBank(int _size) {
10
     size = _size;
12
     size = _size;
11
     pins = new int[size];
13
     pins = new int[size];
26
 
28
 
27
 void GPIOBank::setOutput(void) {
29
 void GPIOBank::setOutput(void) {
28
     for (int i = 0; i < size; i++) {
30
     for (int i = 0; i < size; i++) {
31
+#ifdef GPIO_HIGH_AS_INPUT
29
         pinMode(pins[i], INPUT);
32
         pinMode(pins[i], INPUT);
33
+#else
34
+        pinMode(pins[i], OUTPUT);
35
+        digitalWrite(pins[i], HIGH);
36
+#endif
30
         out_state[i] = true;
37
         out_state[i] = true;
31
     }
38
     }
32
     is_output = true;
39
     is_output = true;
53
     }
60
     }
54
     
61
     
55
     if ((n >= 0) && (n < size)) {
62
     if ((n >= 0) && (n < size)) {
56
-        //digitalWrite(pins[n], (!state) ? HIGH : LOW);
57
-        
63
+#ifdef GPIO_HIGH_AS_INPUT
58
         if (state) {
64
         if (state) {
59
             pinMode(pins[n], OUTPUT);
65
             pinMode(pins[n], OUTPUT);
60
             digitalWrite(pins[n], LOW);
66
             digitalWrite(pins[n], LOW);
61
         } else {
67
         } else {
62
             pinMode(pins[n], INPUT);
68
             pinMode(pins[n], INPUT);
63
         }
69
         }
70
+#else
71
+        digitalWrite(pins[n], (!state) ? HIGH : LOW);
72
+#endif
73
+
64
         out_state[n] = !state;
74
         out_state[n] = !state;
65
         
75
         
66
 #ifdef PLATFORM_ESP
76
 #ifdef PLATFORM_ESP

Loading…
Cancel
Save