Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Created August 10, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsBergqvist/4940c59b4ff0cf5807463fd0873c3ffc to your computer and use it in GitHub Desktop.
Save LarsBergqvist/4940c59b4ff0cf5807463fd0873c3ffc to your computer and use it in GitHub Desktop.
Blynk example without setup() and loop()
#include <Arduino.h> // Arduino basic stuff
#include <WiFi.h> // WiFi-library needed for Blynk
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h> // Include Blynk library
#include "credentials.h" // Keep WiFi and Blynk credentials in a separate file
//
// BEEP/BUZZER
// Called when the value of V1 is written to the Blynk server
// V1 is connected to a button in the GUI. When the button is pressed, the V1=1
// and when it is released V1=0
//
#define BEEP_PIN 17
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
Serial.print("V1 value is: ");
Serial.println(pinValue);
if (pinValue == 1)
{
digitalWrite(BEEP_PIN, HIGH);
}
else
{
digitalWrite(BEEP_PIN, LOW);
}
}
//
// DHT Sensor setup
//
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHTPIN_INDOOR 16
#define DHTTYPE_INDOOR DHT11
DHT dht(DHTPIN_INDOOR, DHTTYPE_INDOOR);
//
// Use a timer to trigger reading of the sensor every 5 seconds
// Write the value to V2 to send it to the Blynk server
//
BlynkTimer timer;
#define TIMER_INTERVAL 5000
void timerEvent()
{
float temperature = dht.readTemperature();
if (!isnan(temperature))
{
Serial.println(temperature);
Blynk.virtualWrite(V2, temperature);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment