Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define BLYNK_DEBUG
- #define BLYNK_PRINT Serial
- #include <ArduinoOTA.h>
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #include <TimeLib.h>
- #include <WidgetRTC.h>
- #include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility -> https://github.com/somhi/ESP_SSD1306
- #include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file) --> https://github.com/adafruit/Adafruit-GFX-Library
- #include <SPI.h> // For SPI comm (needed for not getting compile error)
- #include "settings_base.h"
- #include "globals.h"
- //#include "functions.h"
- //#include "blynk_writes.h"
- //Pin connected to ST_CP of 74HC595
- const int latchPin = 15; //D8
- //Pin connected to SH_CP of 74HC595
- const int clockPin = 14; //D5
- //Pin connected to DS of 74HC595
- const int dataPin = 13; // D7
- int totalRelays = 2; // Number of relays
- int relayState = 0; // default state = off
- int relayArr[] = {12, 16}; // Pins on the Wemos
- char vbutton1 = V1; char vbutton2 = V2;
- char relayVButtons[] = {V1,V2};
- int zone = 0;
- int relayVButton = 0;
- byte data;
- byte dataArray[10];
- /*
- SETUP
- */
- BLYNK_WRITE(V1)
- {
- // Get the state of the VButton
- relayVButton = param.asInt();
- relayControl(relayVButton, 12, 49); // Test led on Wemos pin
- //int bitToSet = 49;
- Serial.println("V1 pressed");
- }
- BLYNK_WRITE(V2)
- {
- // Get the state of the VButton
- relayVButton = param.asInt();
- relayControl(relayVButton, 16, 50); // Test led on Wemos pin
- Serial.println("V2 pressed");
- }
- void setup() {
- pinMode(dataPin, OUTPUT); // All 3 pins are output
- pinMode(clockPin, OUTPUT);
- pinMode(latchPin, OUTPUT);
- // Do some loop through all the relays and buttons for pinMode
- for (int i=0; i<=totalRelays; i++){
- pinMode(relayArr[i], OUTPUT);
- digitalWrite(relayArr[i], 0);
- pinMode(relayVButtons[i], INPUT);
- }
- // COMMUNICATIONS
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- // CONNECT TO BLYNK
- Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS);
- while (Blynk.connect() == false) {}
- // OVER THE AIR UPDATES
- ArduinoOTA.setHostname(OTA_HOSTNAME);
- ArduinoOTA.begin();
- Serial.println(F("Blynk v" BLYNK_VERSION ": Device started"));
- }
- /*
- LOOP
- */
- void loop() {
- Blynk.run();
- ArduinoOTA.handle();
- timer.run();
- }
- void relayControl(int onoff, int relayNumber, int bitToSet){
- if(onoff == 1) // Virtual button set to on
- {
- digitalWrite(relayNumber, HIGH); // set Wemos pin on HIGH (for test)
- registerWrite(bitToSet, HIGH);
- relayState = 1;
- }
- else
- {
- digitalWrite(relayNumber, LOW); // set Wemos pin on HIGH (for test)
- registerWrite(bitToSet, LOW);
- relayState = 0;
- }
- }
- void registerWrite(int whichPin, int whichState) {
- // the bits you want to send
- byte bitsToSend = 0;
- // turn off the output so the pins don't light up
- // while you're shifting bits:
- digitalWrite(latchPin, LOW);
- // turn on the next highest bit in bitsToSend:
- bitWrite(bitsToSend, whichPin, whichState);
- // shift the bits out:
- shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
- // turn on the output so the LEDs can light up:
- digitalWrite(latchPin, HIGH);
- }
- //#define BLYNK_DEBUG
- #define BLYNK_PRINT Serial
- #include <ArduinoOTA.h>
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #include <TimeLib.h>
- #include <WidgetRTC.h>
- #include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility -> https://github.com/somhi/ESP_SSD1306
- #include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file) --> https://github.com/adafruit/Adafruit-GFX-Library
- #include <SPI.h> // For SPI comm (needed for not getting compile error)
- #include "settings_base.h"
- #include "globals.h"
- //#include "functions.h"
- //#include "blynk_writes.h"
- //Pin connected to ST_CP of 74HC595
- const int latchPin = 15; //D8
- //Pin connected to SH_CP of 74HC595
- const int clockPin = 14; //D5
- //Pin connected to DS of 74HC595
- const int dataPin = 13; // D7
- int totalRelays = 2; // Number of relays
- int relayState = 0; // default state = off
- int relayArr[] = {12, 16}; // Pins on the Wemos
- char vbutton1 = V1; char vbutton2 = V2;
- char relayVButtons[] = {V1,V2};
- int zone = 0;
- int relayVButton = 0;
- byte data;
- byte dataArray[10];
- /*
- SETUP
- */
- BLYNK_WRITE(V1)
- {
- // Get the state of the VButton
- relayVButton = param.asInt();
- relayControl(relayVButton, 12, 49); // Test led on Wemos pin
- //int bitToSet = 49;
- Serial.println("V1 pressed");
- }
- BLYNK_WRITE(V2)
- {
- // Get the state of the VButton
- relayVButton = param.asInt();
- relayControl(relayVButton, 16, 50); // Test led on Wemos pin
- Serial.println("V2 pressed");
- }
- void setup() {
- pinMode(dataPin, OUTPUT); // All 3 pins are output
- pinMode(clockPin, OUTPUT);
- pinMode(latchPin, OUTPUT);
- // Do some loop through all the relays and buttons for pinMode
- for (int i=0; i<=totalRelays; i++){
- pinMode(relayArr[i], OUTPUT);
- digitalWrite(relayArr[i], 0);
- pinMode(relayVButtons[i], INPUT);
- }
- // COMMUNICATIONS
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- // CONNECT TO BLYNK
- Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS);
- while (Blynk.connect() == false) {}
- // OVER THE AIR UPDATES
- ArduinoOTA.setHostname(OTA_HOSTNAME);
- ArduinoOTA.begin();
- Serial.println(F("Blynk v" BLYNK_VERSION ": Device started"));
- }
- /*
- LOOP
- */
- void loop() {
- Blynk.run();
- ArduinoOTA.handle();
- timer.run();
- }
- void relayControl(int onoff, int relayNumber, int bitToSet){
- if(onoff == 1) // Virtual button set to on
- {
- digitalWrite(relayNumber, HIGH); // set Wemos pin on HIGH (for test)
- registerWrite(bitToSet, HIGH);
- relayState = 1;
- }
- else
- {
- digitalWrite(relayNumber, LOW); // set Wemos pin on HIGH (for test)
- registerWrite(bitToSet, LOW);
- relayState = 0;
- }
- }
- void registerWrite(int whichPin, int whichState) {
- // the bits you want to send
- byte bitsToSend = 0;
- // turn off the output so the pins don't light up
- // while you're shifting bits:
- digitalWrite(latchPin, LOW);
- // turn on the next highest bit in bitsToSend:
- bitWrite(bitsToSend, whichPin, whichState);
- // shift the bits out:
- shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
- // turn on the output so the LEDs can light up:
- digitalWrite(latchPin, HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement