SHOW:
|
|
- or go back to the newest paste.
1 | - | //#define BLYNK_DEBUG |
1 | + | //#define BLYNK_DEBUG |
2 | - | #define BLYNK_PRINT Serial |
2 | + | #define BLYNK_PRINT Serial |
3 | - | |
3 | + | |
4 | - | #include <ArduinoOTA.h> |
4 | + | #include <ArduinoOTA.h> |
5 | - | #include <ESP8266WiFi.h> |
5 | + | #include <ESP8266WiFi.h> |
6 | - | #include <BlynkSimpleEsp8266.h> |
6 | + | #include <BlynkSimpleEsp8266.h> |
7 | - | #include <TimeLib.h> |
7 | + | #include <TimeLib.h> |
8 | - | #include <WidgetRTC.h> |
8 | + | #include <WidgetRTC.h> |
9 | - | |
9 | + | |
10 | - | #include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility -> https://github.com/somhi/ESP_SSD1306 |
10 | + | #include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility -> https://github.com/somhi/ESP_SSD1306 |
11 | - | #include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file) --> https://github.com/adafruit/Adafruit-GFX-Library |
11 | + | #include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file) --> https://github.com/adafruit/Adafruit-GFX-Library |
12 | - | #include <SPI.h> // For SPI comm (needed for not getting compile error) |
12 | + | #include <SPI.h> // For SPI comm (needed for not getting compile error) |
13 | - | |
13 | + | |
14 | - | |
14 | + | |
15 | - | #include "settings_base.h" |
15 | + | #include "settings_base.h" |
16 | - | #include "globals.h" |
16 | + | #include "globals.h" |
17 | - | //#include "functions.h" |
17 | + | //#include "functions.h" |
18 | - | //#include "blynk_writes.h" |
18 | + | //#include "blynk_writes.h" |
19 | - | |
19 | + | |
20 | - | |
20 | + | |
21 | - | |
21 | + | |
22 | - | //Pin connected to ST_CP of 74HC595 |
22 | + | //Pin connected to ST_CP of 74HC595 |
23 | - | const int latchPin = 15; //D8 |
23 | + | const int latchPin = 15; //D8 |
24 | - | //Pin connected to SH_CP of 74HC595 |
24 | + | //Pin connected to SH_CP of 74HC595 |
25 | - | const int clockPin = 14; //D5 |
25 | + | const int clockPin = 14; //D5 |
26 | - | //Pin connected to DS of 74HC595 |
26 | + | //Pin connected to DS of 74HC595 |
27 | - | const int dataPin = 13; // D7 |
27 | + | const int dataPin = 13; // D7 |
28 | - | |
28 | + | |
29 | - | |
29 | + | |
30 | - | int totalRelays = 2; // Number of relays |
30 | + | int totalRelays = 2; // Number of relays |
31 | - | int relayState = 0; // default state = off |
31 | + | int relayState = 0; // default state = off |
32 | - | int relayArr[] = {12, 16}; // Pins on the Wemos |
32 | + | int relayArr[] = {12, 16}; // Pins on the Wemos |
33 | - | char vbutton1 = V1; char vbutton2 = V2; |
33 | + | char vbutton1 = V1; char vbutton2 = V2; |
34 | - | char relayVButtons[] = {V1,V2}; |
34 | + | char relayVButtons[] = {V1,V2}; |
35 | - | int zone = 0; |
35 | + | int zone = 0; |
36 | - | int relayVButton = 0; |
36 | + | int relayVButton = 0; |
37 | - | byte data; |
37 | + | byte data; |
38 | - | byte dataArray[10]; |
38 | + | byte dataArray[10]; |
39 | - | |
39 | + | |
40 | - | |
40 | + | |
41 | - | /* |
41 | + | /* |
42 | - | SETUP |
42 | + | SETUP |
43 | - | */ |
43 | + | */ |
44 | - | BLYNK_WRITE(V1) |
44 | + | BLYNK_WRITE(V1) |
45 | - | { |
45 | + | { |
46 | - | // Get the state of the VButton |
46 | + | // Get the state of the VButton |
47 | - | relayVButton = param.asInt(); |
47 | + | relayVButton = param.asInt(); |
48 | - | relayControl(relayVButton, 12, 49); // Test led on Wemos pin |
48 | + | relayControl(relayVButton, 12, 49); // Test led on Wemos pin |
49 | - | //int bitToSet = 49; |
49 | + | //int bitToSet = 49; |
50 | - | |
50 | + | |
51 | - | Serial.println("V1 pressed"); |
51 | + | Serial.println("V1 pressed"); |
52 | - | } |
52 | + | } |
53 | - | |
53 | + | |
54 | - | BLYNK_WRITE(V2) |
54 | + | BLYNK_WRITE(V2) |
55 | - | { |
55 | + | { |
56 | - | // Get the state of the VButton |
56 | + | // Get the state of the VButton |
57 | - | relayVButton = param.asInt(); |
57 | + | relayVButton = param.asInt(); |
58 | - | relayControl(relayVButton, 16, 50); // Test led on Wemos pin |
58 | + | relayControl(relayVButton, 16, 50); // Test led on Wemos pin |
59 | - | Serial.println("V2 pressed"); |
59 | + | Serial.println("V2 pressed"); |
60 | - | } |
60 | + | } |
61 | - | |
61 | + | |
62 | - | void setup() { |
62 | + | void setup() { |
63 | - | |
63 | + | |
64 | - | pinMode(dataPin, OUTPUT); // All 3 pins are output |
64 | + | pinMode(dataPin, OUTPUT); // All 3 pins are output |
65 | - | pinMode(clockPin, OUTPUT); |
65 | + | pinMode(clockPin, OUTPUT); |
66 | - | pinMode(latchPin, OUTPUT); |
66 | + | pinMode(latchPin, OUTPUT); |
67 | - | |
67 | + | |
68 | - | // Do some loop through all the relays and buttons for pinMode |
68 | + | // Do some loop through all the relays and buttons for pinMode |
69 | - | for (int i=0; i<=totalRelays; i++){ |
69 | + | for (int i=0; i<=totalRelays; i++){ |
70 | - | pinMode(relayArr[i], OUTPUT); |
70 | + | pinMode(relayArr[i], OUTPUT); |
71 | - | digitalWrite(relayArr[i], 0); |
71 | + | digitalWrite(relayArr[i], 0); |
72 | - | pinMode(relayVButtons[i], INPUT); |
72 | + | pinMode(relayVButtons[i], INPUT); |
73 | - | } |
73 | + | } |
74 | - | |
74 | + | |
75 | - | // COMMUNICATIONS |
75 | + | // COMMUNICATIONS |
76 | - | Serial.begin(115200); |
76 | + | Serial.begin(115200); |
77 | - | WiFi.mode(WIFI_STA); |
77 | + | WiFi.mode(WIFI_STA); |
78 | - | // CONNECT TO BLYNK |
78 | + | // CONNECT TO BLYNK |
79 | - | Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS); |
79 | + | Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS); |
80 | - | while (Blynk.connect() == false) {} |
80 | + | while (Blynk.connect() == false) {} |
81 | - | // OVER THE AIR UPDATES |
81 | + | // OVER THE AIR UPDATES |
82 | - | ArduinoOTA.setHostname(OTA_HOSTNAME); |
82 | + | ArduinoOTA.setHostname(OTA_HOSTNAME); |
83 | - | ArduinoOTA.begin(); |
83 | + | ArduinoOTA.begin(); |
84 | - | |
84 | + | |
85 | - | Serial.println(F("Blynk v" BLYNK_VERSION ": Device started")); |
85 | + | Serial.println(F("Blynk v" BLYNK_VERSION ": Device started")); |
86 | } | |
87 | - | /* |
87 | + | /* |
88 | - | LOOP |
88 | + | LOOP |
89 | - | */ |
89 | + | */ |
90 | - | void loop() { |
90 | + | void loop() { |
91 | - | Blynk.run(); |
91 | + | Blynk.run(); |
92 | - | ArduinoOTA.handle(); |
92 | + | ArduinoOTA.handle(); |
93 | - | timer.run(); |
93 | + | timer.run(); |
94 | } | |
95 | - | |
95 | + | |
96 | - | void relayControl(int onoff, int relayNumber, int bitToSet){ |
96 | + | void relayControl(int onoff, int relayNumber, int bitToSet){ |
97 | - | if(onoff == 1) // Virtual button set to on |
97 | + | if(onoff == 1) // Virtual button set to on |
98 | - | { |
98 | + | { |
99 | - | digitalWrite(relayNumber, HIGH); // set Wemos pin on HIGH (for test) |
99 | + | digitalWrite(relayNumber, HIGH); // set Wemos pin on HIGH (for test) |
100 | - | registerWrite(bitToSet, HIGH); |
100 | + | registerWrite(bitToSet, HIGH); |
101 | - | relayState = 1; |
101 | + | relayState = 1; |
102 | - | } |
102 | + | } |
103 | - | else |
103 | + | else |
104 | - | { |
104 | + | { |
105 | - | digitalWrite(relayNumber, LOW); // set Wemos pin on HIGH (for test) |
105 | + | digitalWrite(relayNumber, LOW); // set Wemos pin on HIGH (for test) |
106 | - | registerWrite(bitToSet, LOW); |
106 | + | registerWrite(bitToSet, LOW); |
107 | - | relayState = 0; |
107 | + | relayState = 0; |
108 | - | } |
108 | + | } |
109 | } | |
110 | - | void registerWrite(int whichPin, int whichState) { |
110 | + | void registerWrite(int whichPin, int whichState) { |
111 | - | // the bits you want to send |
111 | + | // the bits you want to send |
112 | - | byte bitsToSend = 0; |
112 | + | byte bitsToSend = 0; |
113 | - | |
113 | + | |
114 | - | // turn off the output so the pins don't light up |
114 | + | // turn off the output so the pins don't light up |
115 | - | // while you're shifting bits: |
115 | + | // while you're shifting bits: |
116 | - | digitalWrite(latchPin, LOW); |
116 | + | digitalWrite(latchPin, LOW); |
117 | - | |
117 | + | |
118 | - | // turn on the next highest bit in bitsToSend: |
118 | + | // turn on the next highest bit in bitsToSend: |
119 | - | bitWrite(bitsToSend, whichPin, whichState); |
119 | + | bitWrite(bitsToSend, whichPin, whichState); |
120 | - | |
120 | + | |
121 | - | // shift the bits out: |
121 | + | // shift the bits out: |
122 | - | shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); |
122 | + | shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); |
123 | - | |
123 | + | |
124 | - | // turn on the output so the LEDs can light up: |
124 | + | // turn on the output so the LEDs can light up: |
125 | - | digitalWrite(latchPin, HIGH); |
125 | + | digitalWrite(latchPin, HIGH); |
126 | - | |
126 | + | |
127 | } | |
128 | ||
129 | - | //#define BLYNK_DEBUG |
129 | + | //#define BLYNK_DEBUG |
130 | - | #define BLYNK_PRINT Serial |
130 | + | #define BLYNK_PRINT Serial |
131 | - | |
131 | + | |
132 | - | #include <ArduinoOTA.h> |
132 | + | #include <ArduinoOTA.h> |
133 | - | #include <ESP8266WiFi.h> |
133 | + | #include <ESP8266WiFi.h> |
134 | - | #include <BlynkSimpleEsp8266.h> |
134 | + | #include <BlynkSimpleEsp8266.h> |
135 | - | #include <TimeLib.h> |
135 | + | #include <TimeLib.h> |
136 | - | #include <WidgetRTC.h> |
136 | + | #include <WidgetRTC.h> |
137 | - | |
137 | + | |
138 | - | #include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility -> https://github.com/somhi/ESP_SSD1306 |
138 | + | #include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility -> https://github.com/somhi/ESP_SSD1306 |
139 | - | #include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file) --> https://github.com/adafruit/Adafruit-GFX-Library |
139 | + | #include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file) --> https://github.com/adafruit/Adafruit-GFX-Library |
140 | - | #include <SPI.h> // For SPI comm (needed for not getting compile error) |
140 | + | #include <SPI.h> // For SPI comm (needed for not getting compile error) |
141 | - | |
141 | + | |
142 | - | |
142 | + | |
143 | - | #include "settings_base.h" |
143 | + | #include "settings_base.h" |
144 | - | #include "globals.h" |
144 | + | #include "globals.h" |
145 | - | //#include "functions.h" |
145 | + | //#include "functions.h" |
146 | - | //#include "blynk_writes.h" |
146 | + | //#include "blynk_writes.h" |
147 | - | |
147 | + | |
148 | - | |
148 | + | |
149 | - | |
149 | + | |
150 | - | //Pin connected to ST_CP of 74HC595 |
150 | + | //Pin connected to ST_CP of 74HC595 |
151 | - | const int latchPin = 15; //D8 |
151 | + | const int latchPin = 15; //D8 |
152 | - | //Pin connected to SH_CP of 74HC595 |
152 | + | //Pin connected to SH_CP of 74HC595 |
153 | - | const int clockPin = 14; //D5 |
153 | + | const int clockPin = 14; //D5 |
154 | - | //Pin connected to DS of 74HC595 |
154 | + | //Pin connected to DS of 74HC595 |
155 | - | const int dataPin = 13; // D7 |
155 | + | const int dataPin = 13; // D7 |
156 | - | |
156 | + | |
157 | - | |
157 | + | |
158 | - | int totalRelays = 2; // Number of relays |
158 | + | int totalRelays = 2; // Number of relays |
159 | - | int relayState = 0; // default state = off |
159 | + | int relayState = 0; // default state = off |
160 | - | int relayArr[] = {12, 16}; // Pins on the Wemos |
160 | + | int relayArr[] = {12, 16}; // Pins on the Wemos |
161 | - | char vbutton1 = V1; char vbutton2 = V2; |
161 | + | char vbutton1 = V1; char vbutton2 = V2; |
162 | - | char relayVButtons[] = {V1,V2}; |
162 | + | char relayVButtons[] = {V1,V2}; |
163 | - | int zone = 0; |
163 | + | int zone = 0; |
164 | - | int relayVButton = 0; |
164 | + | int relayVButton = 0; |
165 | - | byte data; |
165 | + | byte data; |
166 | - | byte dataArray[10]; |
166 | + | byte dataArray[10]; |
167 | - | |
167 | + | |
168 | - | |
168 | + | |
169 | - | /* |
169 | + | /* |
170 | - | SETUP |
170 | + | SETUP |
171 | - | */ |
171 | + | */ |
172 | - | BLYNK_WRITE(V1) |
172 | + | BLYNK_WRITE(V1) |
173 | - | { |
173 | + | { |
174 | - | // Get the state of the VButton |
174 | + | // Get the state of the VButton |
175 | - | relayVButton = param.asInt(); |
175 | + | relayVButton = param.asInt(); |
176 | - | relayControl(relayVButton, 12, 49); // Test led on Wemos pin |
176 | + | relayControl(relayVButton, 12, 49); // Test led on Wemos pin |
177 | - | //int bitToSet = 49; |
177 | + | //int bitToSet = 49; |
178 | - | |
178 | + | |
179 | - | Serial.println("V1 pressed"); |
179 | + | Serial.println("V1 pressed"); |
180 | - | } |
180 | + | } |
181 | - | |
181 | + | |
182 | - | BLYNK_WRITE(V2) |
182 | + | BLYNK_WRITE(V2) |
183 | - | { |
183 | + | { |
184 | - | // Get the state of the VButton |
184 | + | // Get the state of the VButton |
185 | - | relayVButton = param.asInt(); |
185 | + | relayVButton = param.asInt(); |
186 | - | relayControl(relayVButton, 16, 50); // Test led on Wemos pin |
186 | + | relayControl(relayVButton, 16, 50); // Test led on Wemos pin |
187 | - | Serial.println("V2 pressed"); |
187 | + | Serial.println("V2 pressed"); |
188 | - | } |
188 | + | } |
189 | - | |
189 | + | |
190 | - | void setup() { |
190 | + | void setup() { |
191 | - | |
191 | + | |
192 | - | pinMode(dataPin, OUTPUT); // All 3 pins are output |
192 | + | pinMode(dataPin, OUTPUT); // All 3 pins are output |
193 | - | pinMode(clockPin, OUTPUT); |
193 | + | pinMode(clockPin, OUTPUT); |
194 | - | pinMode(latchPin, OUTPUT); |
194 | + | pinMode(latchPin, OUTPUT); |
195 | - | |
195 | + | |
196 | - | // Do some loop through all the relays and buttons for pinMode |
196 | + | // Do some loop through all the relays and buttons for pinMode |
197 | - | for (int i=0; i<=totalRelays; i++){ |
197 | + | for (int i=0; i<=totalRelays; i++){ |
198 | - | pinMode(relayArr[i], OUTPUT); |
198 | + | pinMode(relayArr[i], OUTPUT); |
199 | - | digitalWrite(relayArr[i], 0); |
199 | + | digitalWrite(relayArr[i], 0); |
200 | - | pinMode(relayVButtons[i], INPUT); |
200 | + | pinMode(relayVButtons[i], INPUT); |
201 | - | } |
201 | + | } |
202 | - | |
202 | + | |
203 | - | // COMMUNICATIONS |
203 | + | // COMMUNICATIONS |
204 | - | Serial.begin(115200); |
204 | + | Serial.begin(115200); |
205 | - | WiFi.mode(WIFI_STA); |
205 | + | WiFi.mode(WIFI_STA); |
206 | - | // CONNECT TO BLYNK |
206 | + | // CONNECT TO BLYNK |
207 | - | Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS); |
207 | + | Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS); |
208 | - | while (Blynk.connect() == false) {} |
208 | + | while (Blynk.connect() == false) {} |
209 | - | // OVER THE AIR UPDATES |
209 | + | // OVER THE AIR UPDATES |
210 | - | ArduinoOTA.setHostname(OTA_HOSTNAME); |
210 | + | ArduinoOTA.setHostname(OTA_HOSTNAME); |
211 | - | ArduinoOTA.begin(); |
211 | + | ArduinoOTA.begin(); |
212 | - | |
212 | + | |
213 | - | Serial.println(F("Blynk v" BLYNK_VERSION ": Device started")); |
213 | + | Serial.println(F("Blynk v" BLYNK_VERSION ": Device started")); |
214 | } | |
215 | - | /* |
215 | + | /* |
216 | - | LOOP |
216 | + | LOOP |
217 | - | */ |
217 | + | */ |
218 | - | void loop() { |
218 | + | void loop() { |
219 | - | Blynk.run(); |
219 | + | Blynk.run(); |
220 | - | ArduinoOTA.handle(); |
220 | + | ArduinoOTA.handle(); |
221 | - | timer.run(); |
221 | + | timer.run(); |
222 | } | |
223 | - | |
223 | + | |
224 | - | void relayControl(int onoff, int relayNumber, int bitToSet){ |
224 | + | void relayControl(int onoff, int relayNumber, int bitToSet){ |
225 | - | if(onoff == 1) // Virtual button set to on |
225 | + | if(onoff == 1) // Virtual button set to on |
226 | - | { |
226 | + | { |
227 | - | digitalWrite(relayNumber, HIGH); // set Wemos pin on HIGH (for test) |
227 | + | digitalWrite(relayNumber, HIGH); // set Wemos pin on HIGH (for test) |
228 | - | registerWrite(bitToSet, HIGH); |
228 | + | registerWrite(bitToSet, HIGH); |
229 | - | relayState = 1; |
229 | + | relayState = 1; |
230 | - | } |
230 | + | } |
231 | - | else |
231 | + | else |
232 | - | { |
232 | + | { |
233 | - | digitalWrite(relayNumber, LOW); // set Wemos pin on HIGH (for test) |
233 | + | digitalWrite(relayNumber, LOW); // set Wemos pin on HIGH (for test) |
234 | - | registerWrite(bitToSet, LOW); |
234 | + | registerWrite(bitToSet, LOW); |
235 | - | relayState = 0; |
235 | + | relayState = 0; |
236 | - | } |
236 | + | } |
237 | } | |
238 | - | void registerWrite(int whichPin, int whichState) { |
238 | + | void registerWrite(int whichPin, int whichState) { |
239 | - | // the bits you want to send |
239 | + | // the bits you want to send |
240 | - | byte bitsToSend = 0; |
240 | + | byte bitsToSend = 0; |
241 | - | |
241 | + | |
242 | - | // turn off the output so the pins don't light up |
242 | + | // turn off the output so the pins don't light up |
243 | - | // while you're shifting bits: |
243 | + | // while you're shifting bits: |
244 | - | digitalWrite(latchPin, LOW); |
244 | + | digitalWrite(latchPin, LOW); |
245 | - | |
245 | + | |
246 | - | // turn on the next highest bit in bitsToSend: |
246 | + | // turn on the next highest bit in bitsToSend: |
247 | - | bitWrite(bitsToSend, whichPin, whichState); |
247 | + | bitWrite(bitsToSend, whichPin, whichState); |
248 | - | |
248 | + | |
249 | - | // shift the bits out: |
249 | + | // shift the bits out: |
250 | - | shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); |
250 | + | shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); |
251 | - | |
251 | + | |
252 | - | // turn on the output so the LEDs can light up: |
252 | + | // turn on the output so the LEDs can light up: |
253 | - | digitalWrite(latchPin, HIGH); |
253 | + | digitalWrite(latchPin, HIGH); |
254 | - | |
254 | + | |
255 | } |