[SOLVED] Virtual Pins - LEDs - WidgetLED - Blynk_Write ARRRUGGGHHHH

And the for loop something like this:

  for (int i=0; i <= 4; i++){  // loop 5 times for 0 to 4
    digitalWrite( 4 , HIGH ); // This is the LED indicating the program has started.
    delay( 50 );  // keep these delays as short as possible especially outside of setup
    digitalWrite( 4 , LOW );
    delay( 50 );
  }

Costas,

Couple things:
I dropped in the code, it tripped errors on virtualWrite. I searched through the DOCs and couldn’t find that, I did find Blynk.virtualWrite so I put that in and the errors went away but the App LED V0 still won’t light up.

I’ve tested all the basic on/off on D 0,1,6,7 both PUSH and SWITCH from the App works great. It’s just the LED on the App. Here is the code we’re at now.

The delay code works great. Very brief and elegant.

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
//
char auth[] = "b2784b3b3c5????2894f8752709100fd";

// Double Door Reed Swith CLOSED 
// ******************************
const int closedreedswitch = A4;
const int closedled = 2;
int hallstateclosed = 0;
//*******************************
//
// Double Door Reed Swith OPEN 
// ******************************
const int openreedswitch = A3;
const int openled = 3;
int hallstateopen = 0;


void setup () 
{
  Serial.begin(9600);
  Blynk.begin(auth);
    

 pinMode( 0 , OUTPUT); // Whole House Fan #1 Motor 4amp
 pinMode( 1 , OUTPUT); // Whole House Fan #2 Motor 4amp
 pinMode(closedreedswitch, INPUT);
 pinMode(closedled, OUTPUT);
// OPEN Reed Setup
 pinMode(openreedswitch, INPUT);
 pinMode(openled, OUTPUT);
 
  pinMode( 6 , OUTPUT); // Door One on Digital Pin D7
  pinMode( 4 , OUTPUT); // LED Indicator Light on Digital Pin D6
  pinMode( 7 , OUTPUT); // Door Two on Digital Pin D5
// The next two lines shutdown the relay so when the power bumps your doors don't pop open. 
  digitalWrite( 7 , LOW ); //Double Garage Door Switch
  digitalWrite( 6 , LOW ); //Single Garage Door Switch
  digitalWrite( 0 , HIGH ); //Whole House Fan #1
  digitalWrite( 1 , HIGH ); //Whole House Fan #2
  delay( 200 ); //rest

  for (int i=0; i <= 4; i++){  // loop 5 times for 0 to 4
    digitalWrite( 4 , HIGH ); // This is the LED indicating the program has started.
    delay( 250 );  // keep these delays as short as possible especially outside of setup
    digitalWrite( 4 , LOW );
    delay( 250 );
  }}

// ---------[ Widget Button using  virtual pin # 0 ]--------------------

BLYNK_WRITE(0) { 
  int hallstateclosed = param.asInt();
  if (hallstateclosed == 0) { 
   Blynk.virtualWrite(V1, 255);
  }
 else{
   Blynk.virtualWrite(V1, 0);
 }
}

void loop() 
{
  Blynk.run();

// CLOSED Reed Part of Loop    
 hallstateclosed = digitalRead(closedreedswitch);

  if (hallstateclosed == LOW){
    digitalWrite(closedled, HIGH);
      }
  else{
    digitalWrite(closedled, LOW);
    
 
/// OPEN Reed Part of Loop

 hallstateopen = digitalRead(openreedswitch); 

  if (hallstateopen == LOW){
    digitalWrite(openled, HIGH);
      }
  else{
    digitalWrite(openled, LOW);
    
   }}}

Yes sorry Blynk.virtualWrite not just virtualWrite.

Have you tried a button set as switch mode in the app to control the virtual LED’s?

I notice you have:

// ---------[ Widget Button using  virtual pin # 0 ]--------------------

BLYNK_WRITE(0) { 
  int hallstateclosed = param.asInt();
  if (hallstateclosed == 0) { 
   Blynk.virtualWrite(V1, 255);
....................

Not sure what this means in Particle speak but in Arduino speak it means you have a button on the app on digital pin 0 and if the button is pressed the virtual LED on virtual pin V1 will light. Is this how your app is configured?

Read your part where you say 'the APP LED V0 still won’t light up". If you are using V0 rather than V1 for the virtual LED then you need Blynk.virtualWrite(V0, 255) etc

I am very confused with your pin settings. Your sketch seems to contradict what pin settings you have in the definitions, pinMode’s and pinMode comments.

I was thinking maybe this is something like the WeMos where you have to translate the pins as shown on the device to GPIO pins that the Arduino IDE can understand. Is this the case or are all your pins mixed up?

A full sketch for you, all tested and working but for Arduino Mega with ESP-01 shield.

Notes:

A. Only virtual pins are controlled with Blynk_Write.
B. I think you will need a different timer for the Photon.
C. Virtual LED’s used in the way shown in this sketch will not respond to HIGH and LOW just 255 and 0.

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#define EspSerial Serial2 // Set ESP8266 Serial object

ESP8266 wifi(EspSerial);

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";
byte digitalcontrol = 0;
byte hasdigitalcontrolchanged = 0;
#include <SimpleTimer.h>
SimpleTimer timer;

void setup()
{
  Serial.begin(115200);  // Set console baud rate
  delay(10);
  EspSerial.begin(115200);  // Set ESP8266 baud rate
  delay(10);
  Blynk.begin(auth, wifi, "Office", "1234567890");
  timer.setInterval(1000,  testdigital); // every 1 second check if D2 is high or low
}

void testdigital(){ // only change LED status if button has changed status
  digitalcontrol = digitalRead(2);
  if(digitalcontrol != hasdigitalcontrolchanged){
    if (digitalcontrol == 1){
       Blynk.virtualWrite(V1, 255);
    }
    else{
      Blynk.virtualWrite(V1, 0);
    }
  }
  hasdigitalcontrolchanged = digitalcontrol;
}

BLYNK_WRITE(V0) { // button on virtual pin 0
  int hallstateclosed = param.asInt();
  if (hallstateclosed == 0) {
    Serial.println("LED should be ON"); 
    Blynk.virtualWrite(V1, 255);  // virtual LED on virtual pin 0
  }
 else{
   Blynk.virtualWrite(V1, 0);
   Serial.println("LED should be OFF"); // virtual LED on virtual pin 0
 }
}

void loop()
{
  Blynk.run();
  timer.run();
}
1 Like

Costas,

WORKS GREAT !!! But you knew that. I wish I had your brains !

Thank you for your patience and your expertise in solving this.

On to the next stage.

Thanks again. :smiley:

Lane