初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This sketch shows how to handle App connected/disconnected events.
NOTE:
Be sure to enable "send app connect command"
in your Project Settings!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// This is called when Smartphone App is opened
BLYNK_APP_CONNECTED() {
Serial.println("App Connected.");
}
// This is called when Smartphone App is closed
BLYNK_APP_DISCONNECTED() {
Serial.println("App Disconnected.");
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}

View File

@@ -0,0 +1,89 @@
/*************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This sketch shows how to access EthernetClient directly in Blynk
1. This gives you full control of the connection process.
2. Shows a sensible way of integrating other connectivity hardware,
that was not supported by Blynk out-of-the-box.
NOTE: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
DON'T use them in your sketch directly!
WARNING: If you have an SD card, you may need to disable it
by setting pin 4 to HIGH. Read more here:
https://www.arduino.cc/en/Main/ArduinoEthernetShield
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// You can specify your board mac adress
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Ethernet shield and SDcard pins
#define W5100_CS 10
#define SDCARD_CS 4
EthernetClient ethernetClient;
// This function tries to connect to the cloud using TCP
bool connectBlynk()
{
ethernetClient.stop();
return ethernetClient.connect(BLYNK_DEFAULT_DOMAIN, BLYNK_DEFAULT_PORT);
}
void setup()
{
// Debug console
Serial.begin(9600);
// Deselect the SD card
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH);
// Initialize Ethernet shield
Ethernet.begin(mac);
delay(1000); // Give the Ethernet shield a second to initialize
connectBlynk();
Blynk.begin(ethernetClient, auth);
}
void loop()
{
// Reconnect to Blynk Cloud
if (!ethernetClient.connected()) {
connectBlynk();
return;
}
Blynk.run();
}

View File

@@ -0,0 +1,101 @@
/*************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This sketch shows how to access WiFiClient directly in Blynk
1. This gives you full control of the connection process.
2. Shows a sensible way of integrating other connectivity hardware,
that was not supported by Blynk out-of-the-box.
NOTE: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleStream.h>
// Your WiFi credentials.
// Set password to "" for open networks.
const char* ssid = "YourNetworkName";
const char* pass = "YourPassword";
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
WiFiClient wifiClient;
// This function tries to connect to the cloud using TCP
bool connectBlynk()
{
wifiClient.stop();
return wifiClient.connect(BLYNK_DEFAULT_DOMAIN, BLYNK_DEFAULT_PORT);
}
// This function tries to connect to your WiFi network
void connectWiFi()
{
Serial.print("Connecting to ");
Serial.println(ssid);
if (pass && strlen(pass)) {
WiFi.begin((char*)ssid, (char*)pass);
} else {
WiFi.begin((char*)ssid);
}
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
connectWiFi();
connectBlynk();
Blynk.begin(wifiClient, auth);
}
void loop()
{
// Reconnect WiFi
if (WiFi.status() != WL_CONNECTED) {
connectWiFi();
return;
}
// Reconnect to Blynk Cloud
if (!wifiClient.connected()) {
connectBlynk();
return;
}
Blynk.run();
}

View File

@@ -0,0 +1,93 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how value can be pushed from Arduino to
the Blynk App.
WARNING :
For this example you'll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library
App project setup:
Value Display widget attached to V5
Value Display widget attached to V6
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
#define DHTPIN 2 // What digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}

View File

@@ -0,0 +1,83 @@
/*************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This sketch shows how to connect to your ESP8266 directly from Blynk App
NOTE: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// This device Access Point credentials.
// Set password to "" to create open network.
const char* ssid = "YourNetworkName";
const char* pass = "YourPassword";
WiFiServer wifiServer(80);
WiFiClient wifiClient;
// This function tries to reconnect to WiFi network
void connectWiFi() {
Serial.print("Configuring access point...");
if (pass && strlen(pass)) {
WiFi.softAP((char*)ssid, (char*)pass);
} else {
WiFi.softAP((char*)ssid);
}
wifiServer.stop();
wifiServer.begin();
Serial.print("Server started: ");
Serial.println(WiFi.softAPIP());
}
void setup() {
Serial.begin(9600);
connectWiFi();
}
void loop() {
// If thereis some client
wifiClient = wifiServer.available();
if (wifiClient)
{
Serial.println("client available");
Blynk.begin(wifiClient, auth);
while (wifiClient.connected())
{
Blynk.run();
}
}
}

View File

@@ -0,0 +1,95 @@
/*************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This sketch shows how to connect to your ESP8266 directly from Blynk App
NOTE: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
const char* ssid = "YourNetworkName";
const char* pass = "YourPassword";
WiFiServer wifiServer(80);
WiFiClient wifiClient;
// This function tries to reconnect to WiFi network
void connectWiFi() {
Serial.print("Connecting to ");
Serial.println(ssid);
if (pass && strlen(pass)) {
WiFi.begin((char*)ssid, (char*)pass);
} else {
WiFi.begin((char*)ssid);
}
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
wifiServer.stop();
wifiServer.begin();
Serial.print("Server started: ");
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(9600);
connectWiFi();
}
void loop() {
// Reconnect WiFi
if (WiFi.status() != WL_CONNECTED) {
connectWiFi();
return;
}
// If thereis some client
wifiClient = wifiServer.available();
if (wifiClient)
{
Serial.println("client available");
Blynk.begin(wifiClient, auth);
while (wifiClient.connected())
{
Blynk.run();
}
}
}

View File

@@ -0,0 +1,72 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You can construct and display any strings on a Value Display.
App project setup:
Value Display widget attached to V5
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendTemperature()
{
// Generate random temperature value 10.0 to 30.0 (for example)
float t = float(random(100, 300)) / 10;
// Format: 1 decimal place, add ℃
String str = String(t, 1) + "";
// Send it to the server
Blynk.virtualWrite(V5, str);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// Setup a function to be called every second
timer.setInterval(1000L, sendTemperature);
}
void loop()
{
Blynk.run();
timer.run();
}

View File

@@ -0,0 +1,80 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how to keep WiFi connection on ESP8266.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
int lastConnectionAttempt = millis();
int connectionDelay = 5000; // try to reconnect every 5 seconds
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
// check WiFi connection:
if (WiFi.status() != WL_CONNECTED)
{
// (optional) "offline" part of code
// check delay:
if (millis() - lastConnectionAttempt >= connectionDelay)
{
lastConnectionAttempt = millis();
// attempt to connect to Wifi network:
if (pass && strlen(pass))
{
WiFi.begin((char*)ssid, (char*)pass);
}
else
{
WiFi.begin((char*)ssid);
}
}
}
else
{
Blynk.run();
}
}

View File

@@ -0,0 +1,87 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
Control a color gradient on NeoPixel strip using a slider!
For this example you need NeoPixel library:
https://github.com/adafruit/Adafruit_NeoPixel
App project setup:
Slider widget (0...500) on V1
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <Adafruit_NeoPixel.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
#define PIN 8
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800);
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
BLYNK_WRITE(V1)
{
int shift = param.asInt();
for (int i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, Wheel(shift & 255));
// OR: strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + shift) & 255));
}
strip.show();
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
strip.begin();
strip.show();
}
void loop()
{
Blynk.run();
}

View File

@@ -0,0 +1,71 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This sketch prints all virtual pin's operations!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// This is called for all virtual pins, that don't have BLYNK_WRITE handler
BLYNK_WRITE_DEFAULT() {
Serial.print("input V");
Serial.print(request.pin);
Serial.println(":");
// Print all parameter values
for (auto i = param.begin(); i < param.end(); ++i) {
Serial.print("* ");
Serial.println(i.asString());
}
}
// This is called for all virtual pins, that don't have BLYNK_READ handler
BLYNK_READ_DEFAULT() {
// Generate random response
int val = random(0, 100);
Serial.print("output V");
Serial.print(request.pin);
Serial.print(": ");
Serial.println(val);
Blynk.virtualWrite(request.pin, val);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}

View File

@@ -0,0 +1,84 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows you how you can use server as storage for
your data like EEPROM
Project setup in the Blynk app (not necessary):
Value display on V1 in PUSH mode.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
BlynkTimer timer;
int uptimeCounter;
String someStaticData = "SomeStaticData";
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
//get data stored in virtual pin V0 from server
Blynk.syncVirtual(V0);
}
// restoring counter from server
BLYNK_WRITE(V0)
{
//restoring int value
uptimeCounter = param[0].asInt();
//restoring string value
someStaticData = param[1].asString();
}
void increment() {
uptimeCounter++;
//storing int and string in V0 pin on server
Blynk.virtualWrite(V0, uptimeCounter, someStaticData);
//updating value display with uptimeCounter
Blynk.virtualWrite(V1, uptimeCounter);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
timer.setInterval(1000L, increment);
}
void loop()
{
Blynk.run();
timer.run();
}

View File

@@ -0,0 +1,78 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows you how you can use server as storage for
your data like EEPROM
Project setup in the Blynk app (not necessary):
Value display on V0 in PUSH mode.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
BlynkTimer timer;
int uptimeCounter;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
//get data stored in virtual pin V0 from server
Blynk.syncVirtual(V0);
}
// restoring counter from server
BLYNK_WRITE(V0)
{
//restoring int value
uptimeCounter = param.asInt();
}
void increment() {
uptimeCounter++;
//storing int in V0 pin on server
Blynk.virtualWrite(V0, uptimeCounter);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
timer.setInterval(1000L, increment);
}
void loop()
{
Blynk.run();
timer.run();
}

View File

@@ -0,0 +1,71 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You can set predefined properties of any widget. Like color, label
Project setup in the Blynk app:
Menu Widget on V1 with 2 items
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
BLYNK_WRITE(V1) {
int value = param.asInt();
if (value == 1) {
Serial.println("Item 1 selected");
} else if (value == 2) {
// If item 2 is selected, change menu items...
BlynkParamAllocated items(128); // list length, in bytes
items.add("New item 1");
items.add("New item 2");
items.add("New item 3");
Blynk.setProperty(V1, "labels", items);
// You can also use it like this:
//Blynk.setProperty(V1, "labels", "item 1", "item 2", "item 3");
} else {
Serial.println("Unknown item selected");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}

View File

@@ -0,0 +1,81 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You can set predefined properties of any widget. Like color, label
Project setup in the Blynk app:
Gauge widget (0...100) on V0 in PUSH mode
Slider widget (0...100) on V1
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
#define BLYNK_GREEN "#23C48E"
#define BLYNK_BLUE "#04C0F8"
#define BLYNK_YELLOW "#ED9D00"
#define BLYNK_RED "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"
String gaugeColor;
BLYNK_WRITE(V1) {
int gaugeValue = param.asInt();
String newColor;
if (gaugeValue > 80) {
newColor = BLYNK_RED;
} else if (gaugeValue > 50) {
newColor = BLYNK_YELLOW;
} else {
newColor = BLYNK_GREEN;
}
// Send only if changed
if (newColor != gaugeColor) {
gaugeColor = newColor;
Blynk.setProperty(V0, "color", gaugeColor);
}
Blynk.virtualWrite(V0, gaugeValue);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}

View File

@@ -0,0 +1,94 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This is a simple stroboscope.
You can turn it on and of using a button,
and control frequency with a slider.
App project setup:
Button widget (Switch) on V1
Slider widget (100...1000) on V2
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
#define LED_PIN 9
BlynkTimer timer;
int t1;
// Toggle LED
void ledBlynk()
{
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
}
// Enable/disable blinking using virtual pin 1
BLYNK_WRITE(V1)
{
if (param.asInt()) {
timer.enable(t1);
} else {
timer.disable(t1);
digitalWrite(LED_PIN, LOW);
}
}
// Change blink interval using virtual pin 2
BLYNK_WRITE(V2)
{
long interval = param.asLong();
boolean wasEnabled = timer.isEnabled(t1);
timer.deleteTimer(t1);
t1 = timer.setInterval(interval, ledBlynk);
if (!wasEnabled) {
timer.disable(t1);
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// Configure LED and timer
pinMode(LED_PIN, OUTPUT);
t1 = timer.setInterval(500L, ledBlynk);
timer.disable(t1);
}
void loop()
{
Blynk.run();
timer.run();
}

View File

@@ -0,0 +1,87 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how to monitor a button state
using interrupts mechanism.
App project setup:
LED widget on V1
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
WidgetLED led1(V1);
// We make these values volatile, as they are used in interrupt context
volatile bool pinChanged = false;
volatile int pinValue = 0;
// Most boards won't send data to WiFi out of interrupt handler.
// We just store the value and process it in the main loop.
void checkPin()
{
// Invert state, since button is "Active LOW"
pinValue = !digitalRead(2);
// Mark pin value changed
pinChanged = true;
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// Make pin 2 HIGH by default
pinMode(2, INPUT_PULLUP);
// Attach INT to our handler
attachInterrupt(digitalPinToInterrupt(2), checkPin, CHANGE);
}
void loop()
{
Blynk.run();
if (pinChanged) {
// Process the value
if (pinValue) {
led1.on();
} else {
led1.off();
}
// Clear the mark, as we have processed the value
pinChanged = false;
}
}

View File

@@ -0,0 +1,79 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how to monitor a button state
using polling mechanism.
App project setup:
LED widget on V1
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
int prevState = -1;
int currState = -1;
long lastChangeTime = 0;
void checkPin()
{
// Invert state, since button is "Active LOW"
int state = !digitalRead(2);
// Debounce mechanism
long t = millis();
if (state != prevState) {
lastChangeTime = t;
}
if (t - lastChangeTime > 50) {
if (state != currState) {
currState = state;
Blynk.virtualWrite(V1, state);
}
}
prevState = state;
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// Make pin 2 default HIGH, and attach INT to our handler
pinMode(2, INPUT_PULLUP);
}
void loop()
{
Blynk.run();
checkPin();
}

View File

@@ -0,0 +1,80 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You can synchronize the state of widgets with hardware states,
even if hardware resets or looses connection temporarily
Project setup in the Blynk app:
Slider widget (0...1024) on V0
Value display (0...1024) on V2
Button widget on digital pin (connected to an LED)
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
// You can also update individual virtual pins like this:
//Blynk.syncVirtual(V0, V2);
// Let's write your hardware uptime to Virtual Pin 2
int value = millis() / 1000;
Blynk.virtualWrite(V2, value);
}
BLYNK_WRITE(V0)
{
// Use of syncAll() will cause this function to be called
// Parameter holds last slider value
int sliderValue0 = param.asInt();
}
BLYNK_WRITE(V2)
{
// You'll get uptime value here as result of syncAll()
int uptime = param.asInt();
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}

View File

@@ -0,0 +1,104 @@
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how to synchronize Button widget
and physical button state.
App project setup:
Button widget attached to V2 (Switch mode)
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Set your LED and physical button pins here
const int ledPin = 7;
const int btnPin = 8;
BlynkTimer timer;
void checkPhysicalButton();
int ledState = LOW;
int btnState = HIGH;
// Every time we connect to the cloud...
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V2);
// Alternatively, you could override server state using:
//Blynk.virtualWrite(V2, ledState);
}
// When App button is pushed - switch the state
BLYNK_WRITE(V2) {
ledState = param.asInt();
digitalWrite(ledPin, ledState);
}
void checkPhysicalButton()
{
if (digitalRead(btnPin) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {
// Toggle LED state
ledState = !ledState;
digitalWrite(ledPin, ledState);
// Update Button Widget
Blynk.virtualWrite(V2, ledState);
}
btnState = LOW;
} else {
btnState = HIGH;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
pinMode(ledPin, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
digitalWrite(ledPin, ledState);
// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);
}
void loop()
{
Blynk.run();
timer.run();
}