瀏覽代碼

properly switch relais gpios high when inactive.

Thomas Buck 3 年之前
父節點
當前提交
30aa0a8a35
共有 1 個檔案被更改,包括 12 行新增2 行删除
  1. 12
    2
      src/GPIOBank.cpp

+ 12
- 2
src/GPIOBank.cpp 查看文件

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

Loading…
取消
儲存