• NodeMcu ESP8266 V3 Lua CH340 Wifi Dev. Board
• android p
• Blynk server
• Blynk Library version 0.6.1
#define BLYNK_PRINT Serial
#include "FastLED.h"
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define LED_PIN 3
#define NUM_LEDS 3 // Number of LEDs connected.
#define BRIGHTNESS 64 // Default LED brightness.
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];
char auth[] = "";
char ssid[] = "";
char pass[] = "";
BlynkTimer timer;
void checkPhysicalButton();
//---variables for our RGB values (0-1023) ---
int r = 0;
int g = 0;
int b = 0;
//---variables for On/Off, and Auto/Manual toggle
int autoMode = 0;
//--- int/byte for automatic hue incrementation---
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
bool rele;
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V0);
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
Blynk.syncVirtual(V5);
Blynk.syncVirtual(V6);
Blynk.syncVirtual(V7);
Blynk.syncVirtual(V8);
}
// Button 1
BLYNK_WRITE(V0) {
rele = param.asInt();
digitalWrite(D1, rele);
}
// Button 2
BLYNK_WRITE(V1) {
rele = param.asInt();
digitalWrite(D4, rele);
}
// Button 3
BLYNK_WRITE(V2){
rele = param.asInt();
digitalWrite(D5, rele);
}
// Button 4
BLYNK_WRITE(V3)
{
rele = param.asInt();
digitalWrite(D8, rele);
}
//--- Toggle Auto/Manual Mode ---
BLYNK_WRITE(V4) {
autoMode = param.asInt();
}
//--- Red slider value---
BLYNK_WRITE(V6)
{
r = param.asInt();
}
BLYNK_WRITE(V7) {
g = param.asInt();
}
//--- Blue slider value---
BLYNK_WRITE(V8) {
b = param.asInt();
}
void checkPhysicalButton()
{
if (digitalRead(D7))
{
rele = !rele;
digitalWrite(D8, rele);
Blynk.virtualWrite(V3, rele);
delay (450);
}
if (digitalRead(D0))
{
rele = !rele;
digitalWrite(D4, rele);
Blynk.virtualWrite(V1, rele);
delay (450);
}
if (digitalRead(D6))
{
rele = !rele;
digitalWrite(D5, rele);
Blynk.virtualWrite(V2, rele);
delay (450);
}
if (digitalRead(D2))
{
rele = !rele;
digitalWrite(D1, rele);
Blynk.virtualWrite(V0, rele);
delay (450);
}
}
void setup()
{
// Debug console
Serial.begin(9600);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness(BRIGHTNESS);
#define FRAMES_PER_SECOND 120
pinMode(D1, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D8, OUTPUT);
pinMode(D2, INPUT);
pinMode(D0, INPUT);
pinMode(D6, INPUT);
pinMode(D7, INPUT);
// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
if(autoMode == 0) {
for (int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB(r, g, b);
FastLED.show();
delay(30);
}
}
if(autoMode == 1 ) {
fill_rainbow( leds, NUM_LEDS, gHue, 7);
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS(20) {
gHue++; // slowly cycle the "base color" through the rainbow
}
}
Blynk.run();
timer.run();
}