下載Blynk之APP
註冊帳號
點開APP並登入
點黑色區域新增方塊擺放如上圖
程式碼
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "qYS-UhRWkSSMqbG7fLje5yDyiKtmvMyo";
char ssid[] = "LJH";
char pass[] = "1234567890";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
//--------------------------------
BLYNK_WRITE(V1) {
int value = param.asInt(); //以整個型態取得參數
Serial.printf("Left rotate V1=%d\n", value);
}
//--------------------------------
BLYNK_WRITE(V2) {
int value = param.asInt(); //以整個型態取得參數
Serial.printf("Right Rotate V2=%d\n", value);
}
//--------------------------------
BLYNK_WRITE(V3) {
int value = param.asInt(); //以整個型態取得參數
Serial.printf("Pili V3=%d\n", value);
}
//--------------------------------
BLYNK_WRITE(V4) {
int value = param.asInt(); //以整個型態取得參數
Serial.printf("custom V4=%d\n", value);
}
//--------------------------------
BLYNK_WRITE(V5) {
int value = param.asInt(); //以整個型態取得參數
Serial.printf("Red V5=%d\n", value);
}
//--------------------------------
BLYNK_WRITE(V6) {
int value = param.asInt(); //以整個型態取得參數
Serial.printf("Green V6=%d\n", value);
}
//--------------------------------
BLYNK_WRITE(V7) {
int value = param.asInt(); //以整個型態取得參數
Serial.printf("Blue V7=%d\n", value);
}
執行結果
手機開啟個人熱點,連接上IC,使用手機控制IC達到遠端操控之效果
程式碼
#include <SimpleTimer.h>
SimpleTimer ABC;
#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUMPIXELS 24
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "qYS-UhRWkSSMqbG7fLje5yDyiKtmvMyo";
char ssid[] = "LJH";
char pass[] = "1234567890";
int LedMode = 0;
int red = 50 , green = 50, blue = 50 ;
void LeftRotate() {
int static count = 0;
count = count + 1;
if (count > 24)count = 0;
Serial.print("LeftRotate=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 1, red, green, blue);
}
void RightRotate() {
int static count = 24;
count = count - 1;
if (count < 0)count = 24;
Serial.print("RightRotate=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 1, red, green, blue);
}
void Pili() {
int static count = 0;
count = count + 1;
if (count > 24)count = 0;
Serial.print("Pili=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 1, red, green, blue);
LedFromToColor(NUMPIXELS - 2 - count, 1, red, green, blue);
}
void Custom() {
int static count = 24;
count = count - 1;
if (count < 0)count = 24;
Serial.print("Custom=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 24, red, green, blue);
}
void lighton() {
int static count = 24;
Serial.print("Custom=");
Serial.println(count);
AllLedColor(255, 255, 255);
LedFromToColor(count, 24, 255, 255, 255);
}
void lightoff() {
int static count = 24;
Serial.print("Custom=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 24, 0, 0, 0);
}
void WS2812Control()
{
switch (LedMode)
{ case 0: LeftRotate(); break;
case 1: RightRotate(); break;
case 2: Pili(); break;
case 3: Custom(); break;
case 4: lighton(); break;
case 5: lightoff(); break;
}
}
void setup()
{
strip.begin();
Serial.begin(9600);
ABC.setInterval(100, WS2812Control);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
ABC.run();
}
BLYNK_WRITE(V1) {
int value = param.asInt();
Serial.printf("LEFT V1=%d\n", value);
LedMode = 0;
}
BLYNK_WRITE(V2) {
int value = param.asInt();
Serial.printf("RIGHT V2=%d\n", value);
LedMode = 1;
}
BLYNK_WRITE(V3) {
int value = param.asInt();
Serial.printf("PILI V3=%d\n", value);
LedMode = 2;
}
BLYNK_WRITE(V4) {
int value = param.asInt();
Serial.printf("CUSTOM V4=%d\n", value);
LedMode = 3;
}
BLYNK_WRITE(V5) {
int value = param.asInt();
Serial.printf("RED V5=%d\n", value);
red = value;
}
BLYNK_WRITE(V6) {
int value = param.asInt();
Serial.printf("GREEN V6=%d\n", value);
green = value;
}
BLYNK_WRITE(V7) {
int value = param.asInt();
Serial.printf("BLUE V7=%d\n", value);
blue = value;
}
BLYNK_WRITE(V8) {
int value = param.asInt();
Serial.printf("BLUE V8=%d\n", value);
LedMode = 4;
}
接線圖
影片說明