BRLAB DOCS
HomeTutorialsHardware
IoT Relays with Particle and Blynk
IoT Relays with Particle and Blynk
  • Introduction
  • Getting Started
    • What You Will Need
    • Claim Your Particle Device
    • Setup Your Blynk Account
  • Creating the Web Dashboard
    • Template
    • Data Streams
    • Widgets
    • Widget Settings
    • Finished Web Dashboard
  • Creating the Mobile App
    • Blynk.App
    • Widgets
    • Widget Settings
  • The App Code
    • Particle Web IDE
    • Blynk Library
    • Writing The Code
      • Comment Header
      • Define Blynk Objects
      • Define Global Variables
      • Void Setup()
      • Void Loop()
      • BLYNK_WRITE()
    • Application Code
    • Control The World Around You
  • Resources
    • Blynk Documentation
    • Particle Documentation
Powered by GitBook
On this page
  1. The App Code
  2. Writing The Code

BLYNK_WRITE()

BLYNK_WRITE() is a function that is called each time that the device gets an update from the server for a virtual pin.

Therefore this is the function we will use to read and then write the current virtual pin value we get from the Blynk cloud when you change it in the mobile app or web dashboard.

BLYNK_WRITE(V0)
{
    if(param.asint() != relayState1)
    {
        relayState1 = !relayState1; // Toggle state
        // set the relay output pin to the state of the of relayState1 variable
        digitalWrite(relay1, relayState1); 
}
BLYNK_WRITE(V1)
{
    if(param.asint() != relayState2)
    {
        relayState2 = !relayState2; // Toggle state
        // set the relay output pin to the state of the of relayState2 variable
        digitalWrite(relay2, relayState2); 
}
BLYNK_WRITE(V2)
{
    if(param.asint() != relayState3)
    {
        relayState3 = !relayState3; // Toggle state
        // set the relay output pin to the state of the of relayState3 variable
        digitalWrite(relay3, relayState3); 
}
BLYNK_WRITE(V3)
{
    if(param.asint() != relayState4)
    {
        relayState4 = !relayState4; // Toggle state
        // set the relay output pin to the state of the of relayState4 variable
        digitalWrite(relay4, relayState4); 
}
PreviousVoid Loop()NextApplication Code

Last updated 2 years ago