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); 
}

Last updated