first commit
This commit is contained in:
89
libraries/Blynk/examples/More/DHT11/DHT11.ino
Normal file
89
libraries/Blynk/examples/More/DHT11/DHT11.ino
Normal file
@@ -0,0 +1,89 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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 dashboard 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
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
#include <DHT.h>
|
||||
|
||||
#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)
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
dht.begin();
|
||||
|
||||
// Setup a function to be called every second
|
||||
timer.setInterval(1000L, sendSensor);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
timer.run();
|
||||
}
|
||||
|
||||
68
libraries/Blynk/examples/More/FormatString/FormatString.ino
Normal file
68
libraries/Blynk/examples/More/FormatString/FormatString.ino
Normal file
@@ -0,0 +1,68 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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 dashboard setup:
|
||||
Value Display widget attached to V5
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
BlynkTimer timer;
|
||||
|
||||
// This function sends Arduino's up time every second to Virtual Pin (5)
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
// Setup a function to be called every second
|
||||
timer.setInterval(1000L, sendTemperature);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
timer.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
|
||||
// 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(BLYNK_AUTH_TOKEN, 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();
|
||||
}
|
||||
}
|
||||
85
libraries/Blynk/examples/More/NeoPixel/NeoPixel.ino
Normal file
85
libraries/Blynk/examples/More/NeoPixel/NeoPixel.ino
Normal file
@@ -0,0 +1,85 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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 dashboard setup:
|
||||
Slider widget (0...500) on V1
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
strip.begin();
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://twitter.com/blynk_app
|
||||
|
||||
Blynk library is licensed under MIT license
|
||||
This example code is in public domain.
|
||||
|
||||
*************************************************************
|
||||
This example uses BLYNK_WRITE_DEFAULT to capture arbitrary
|
||||
virtual pin changes. This may be useful if you have lots
|
||||
of DataStreams with controls.
|
||||
It also shows how to iterate over all parameter values.
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Debug console
|
||||
Serial.begin(9600);
|
||||
|
||||
Blynk.begin(BLYNK_AUTH_TOKEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
105
libraries/Blynk/examples/More/RTC/RTC.ino
Normal file
105
libraries/Blynk/examples/More/RTC/RTC.ino
Normal file
@@ -0,0 +1,105 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://twitter.com/blynk_app
|
||||
|
||||
Blynk library is licensed under MIT license
|
||||
This example code is in public domain.
|
||||
|
||||
*************************************************************
|
||||
|
||||
Blynk can provide your device with time data, like an RTC.
|
||||
Please note that the accuracy of this method is up to several seconds.
|
||||
|
||||
Datastream setup:
|
||||
Virtual Pin V1, type: String
|
||||
Virtual Pin V2, type: String
|
||||
|
||||
App dashboard setup:
|
||||
Value Display widget on V1
|
||||
Value Display widget on V2
|
||||
|
||||
NOTE: On Web dashboard, use Label widgets
|
||||
|
||||
WARNING:
|
||||
For this example you'll need Time keeping library:
|
||||
https://github.com/PaulStoffregen/Time
|
||||
|
||||
This code is based on an example from the Time library:
|
||||
https://github.com/PaulStoffregen/Time/blob/master/examples/TimeSerial/TimeSerial.ino
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
#include <TimeLib.h>
|
||||
#include <WidgetRTC.h>
|
||||
|
||||
BlynkTimer timer;
|
||||
|
||||
WidgetRTC rtc;
|
||||
|
||||
// Digital clock display of the time
|
||||
void clockDisplay()
|
||||
{
|
||||
// You can call hour(), minute(), ... at any time
|
||||
// Please see Time library examples for details
|
||||
|
||||
String currentTime = String(hour()) + ":" + minute() + ":" + second();
|
||||
String currentDate = String(day()) + " " + month() + " " + year();
|
||||
Serial.print("Current time: ");
|
||||
Serial.print(currentTime);
|
||||
Serial.print(" ");
|
||||
Serial.print(currentDate);
|
||||
Serial.println();
|
||||
|
||||
// Send time to the App
|
||||
Blynk.virtualWrite(V1, currentTime);
|
||||
// Send date to the App
|
||||
Blynk.virtualWrite(V2, currentDate);
|
||||
}
|
||||
|
||||
BLYNK_CONNECTED() {
|
||||
// Synchronize time on connection
|
||||
rtc.begin();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Debug console
|
||||
Serial.begin(9600);
|
||||
|
||||
Blynk.begin(BLYNK_AUTH_TOKEN);
|
||||
|
||||
// Other Time library functions can be used, like:
|
||||
// timeStatus(), setSyncInterval(interval)...
|
||||
// Read more: http://www.pjrc.com/teensy/td_libs_Time.html
|
||||
|
||||
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
|
||||
|
||||
// Display digital clock every 10 seconds
|
||||
timer.setInterval(10000L, clockDisplay);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
timer.run();
|
||||
}
|
||||
|
||||
67
libraries/Blynk/examples/More/RTC_Advanced/RTC_Advanced.ino
Normal file
67
libraries/Blynk/examples/More/RTC_Advanced/RTC_Advanced.ino
Normal file
@@ -0,0 +1,67 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://twitter.com/blynk_app
|
||||
|
||||
Blynk library is licensed under MIT license
|
||||
This example code is in public domain.
|
||||
|
||||
*************************************************************
|
||||
|
||||
Blynk can provide your device with time data, like an RTC.
|
||||
Please note that the accuracy of this method is up to several seconds.
|
||||
|
||||
NOTE: there's a better way to get a detailed time and timezone info.
|
||||
See TimeAndLocation example for details!
|
||||
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
BlynkTimer timer;
|
||||
|
||||
void requestTime() {
|
||||
Blynk.sendInternal("rtc", "sync");
|
||||
}
|
||||
|
||||
BLYNK_WRITE(InternalPinRTC) {
|
||||
long t = param.asLong();
|
||||
Serial.print("Unix time: ");
|
||||
Serial.print(t);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Debug console
|
||||
Serial.begin(9600);
|
||||
|
||||
Blynk.begin(BLYNK_AUTH_TOKEN);
|
||||
|
||||
timer.setInterval(10000L, requestTime);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
timer.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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
|
||||
|
||||
App dashboard setup (optional):
|
||||
Value display on V1
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
timer.setInterval(1000L, increment);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
timer.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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
|
||||
|
||||
App dashboard setup (optional):
|
||||
Value display on V0
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
timer.setInterval(1000L, increment);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
timer.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://twitter.com/blynk_app
|
||||
|
||||
Blynk library is licensed under MIT license
|
||||
This example code is in public domain.
|
||||
|
||||
*************************************************************
|
||||
|
||||
You can set predefined properties (color, label, ...) of any widget.
|
||||
Read more: https://docs.blynk.io/en/blynk.edgent-firmware-api/widget-properties
|
||||
|
||||
Datastream setup:
|
||||
Virtual Pin V1, type: Integer, min: 1, max: 3
|
||||
|
||||
App dashboard setup:
|
||||
Menu Widget on V1 with 2 items: "Item 1", "Add items"
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://twitter.com/blynk_app
|
||||
|
||||
Blynk library is licensed under MIT license
|
||||
This example code is in public domain.
|
||||
|
||||
*************************************************************
|
||||
|
||||
You can set predefined properties (color, label, ...) of any widget.
|
||||
Read more: https://docs.blynk.io/en/blynk.edgent-firmware-api/widget-properties
|
||||
|
||||
App dashboard setup:
|
||||
Gauge widget (0...100) on V0
|
||||
Slider widget (0...100) on V1
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
#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(BLYNK_AUTH_TOKEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
87
libraries/Blynk/examples/More/Stroboscope/Stroboscope.ino
Normal file
87
libraries/Blynk/examples/More/Stroboscope/Stroboscope.ino
Normal file
@@ -0,0 +1,87 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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 dashboard 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
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
#define LED_PIN 4
|
||||
|
||||
BlynkTimer timer;
|
||||
BlynkTimer::Handle t1;
|
||||
|
||||
// Toggle LED
|
||||
void ledBlynk()
|
||||
{
|
||||
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
|
||||
}
|
||||
|
||||
// Enable/disable blinking using virtual pin 1
|
||||
BLYNK_WRITE(V1)
|
||||
{
|
||||
if (param.asInt()) {
|
||||
t1.enable();
|
||||
} else {
|
||||
t1.disable();
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
// Change blink interval using virtual pin 2
|
||||
BLYNK_WRITE(V2)
|
||||
{
|
||||
long interval = param.asLong();
|
||||
t1.changeInterval(interval);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Debug console
|
||||
Serial.begin(9600);
|
||||
|
||||
Blynk.begin(BLYNK_AUTH_TOKEN);
|
||||
|
||||
// Configure LED and timer
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
t1 = timer.setInterval(500L, ledBlynk);
|
||||
t1.disable();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
timer.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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 dashboard setup:
|
||||
LED widget on V1
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
77
libraries/Blynk/examples/More/Sync/ButtonPoll/ButtonPoll.ino
Normal file
77
libraries/Blynk/examples/More/Sync/ButtonPoll/ButtonPoll.ino
Normal file
@@ -0,0 +1,77 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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 dashboard setup:
|
||||
LED widget on V1
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
// Make pin 2 default HIGH, and attach INT to our handler
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
checkPin();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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
|
||||
|
||||
App dashboard setup:
|
||||
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
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
// 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(BLYNK_AUTH_TOKEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://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 dashboard setup:
|
||||
Button widget attached to V2 (Switch mode)
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
// Set your LED and physical button pins here
|
||||
const int ledPin = 13;
|
||||
const int btnPin = 12;
|
||||
|
||||
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(BLYNK_AUTH_TOKEN);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*************************************************************
|
||||
Blynk is a platform with iOS and Android apps to control
|
||||
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
|
||||
You can easily build mobile and web interfaces for any
|
||||
projects by simply dragging and dropping widgets.
|
||||
|
||||
Downloads, docs, tutorials: https://www.blynk.io
|
||||
Sketch generator: https://examples.blynk.cc
|
||||
Blynk community: https://community.blynk.cc
|
||||
Follow us: https://www.fb.com/blynkapp
|
||||
https://twitter.com/blynk_app
|
||||
|
||||
Blynk library is licensed under MIT license
|
||||
This example code is in public domain.
|
||||
|
||||
*************************************************************
|
||||
|
||||
Blynk can provide your device with time and location data.
|
||||
NOTE: the accuracy of this method is up to several seconds.
|
||||
|
||||
*************************************************************/
|
||||
|
||||
/* Comment this out to disable prints and save space */
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
/* Fill in information from Blynk Device Info here */
|
||||
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
//#define BLYNK_TEMPLATE_NAME "Device"
|
||||
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <BlynkSimpleEthernet.h>
|
||||
|
||||
BLYNK_CONNECTED() {
|
||||
// Send requests for different internal data
|
||||
// Request what is actually needed for your use-case
|
||||
Blynk.sendInternal("utc", "tz_name"); // Name of timezone
|
||||
Blynk.sendInternal("utc", "iso"); // ISO-8601 formatted time
|
||||
Blynk.sendInternal("utc", "time"); // Unix timestamp (with msecs)
|
||||
Blynk.sendInternal("utc", "tz"); // Timezone and DST offsets
|
||||
Blynk.sendInternal("utc", "tz_rule"); // POSIX TZ rule
|
||||
Blynk.sendInternal("utc", "dst_next"); // Up to 2 next time offset changes (due to DST)
|
||||
}
|
||||
|
||||
// Receive UTC data
|
||||
BLYNK_WRITE(InternalPinUTC) {
|
||||
String cmd = param[0].asStr();
|
||||
if (cmd == "time") {
|
||||
uint64_t utc_time = param[1].asLongLong();
|
||||
Serial.print("Unix time (UTC): "); Serial.println((uint32_t)(utc_time/1000));
|
||||
|
||||
} else if (cmd == "iso") {
|
||||
String iso_time = param[1].asStr();
|
||||
Serial.print("ISO-8601 time: "); Serial.println(iso_time);
|
||||
|
||||
} else if (cmd == "tz") {
|
||||
long tz_offset = param[1].asInt();
|
||||
long dst_offset = param[2].asInt();
|
||||
Serial.print("TZ offset: "); Serial.print(tz_offset); Serial.println(" minutes");
|
||||
Serial.print("DST offset: "); Serial.print(dst_offset); Serial.println(" minutes");
|
||||
|
||||
} else if (cmd == "tz_name") {
|
||||
String tz_name = param[1].asStr();
|
||||
Serial.print("Timezone: "); Serial.println(tz_name);
|
||||
|
||||
} else if (cmd == "tz_rule") {
|
||||
String tz_rule = param[1].asStr();
|
||||
Serial.print("POSIX TZ rule: "); Serial.println(tz_rule);
|
||||
|
||||
} else if (cmd == "dst_next") {
|
||||
uint32_t next1_ts = param[1].asLong();
|
||||
int next1_off = param[2].asInt();
|
||||
uint32_t next2_ts = param[3].asLong();
|
||||
int next2_off = param[4].asInt();
|
||||
|
||||
Serial.print("Next offset changes: ");
|
||||
Serial.print(next1_off); Serial.print("min. on "); Serial.print(next1_ts);
|
||||
Serial.print(", ");
|
||||
Serial.print(next2_off); Serial.print("min. on "); Serial.print(next2_ts);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Debug console
|
||||
Serial.begin(115200);
|
||||
|
||||
Blynk.begin(BLYNK_AUTH_TOKEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user