Help with my Code plz

am trying to use the IF statement so wen the D7 high the LCD will show Garage Open
wen the D7 LOW the LCD will show garage closed .
in the LCD its just showing garage closed .

plz help me with the code if there is some thing wrong

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"

// This #include statement was automatically added by the Particle IDE.
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * Output any data on LCD widget!
 *
 * App project setup:
 *   LCD widget, switch to ADVANCED mode, select pin V1
 *
 **************************************************************/
#define BLYNK_PRINT Serial
#define Red D7


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "af4a41b131974d91bbaac4d7a3709d4c";

WidgetLCD lcd(V1);

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  
  pinMode(Red,OUTPUT);
 // digitalWrite(Red,HIGH);

  while (Blynk.connect() == false) {
    // Wait until connected
  }
 
  //int Red = digitalWrite(D7)
//  if (Red == LOW)
//  {
 if (Red == HIGH) {
    //digitalWrite(Red, HIGH);
  

  lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Garage"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Open");
   //lcd.clear();
  // Please use timed events when LCD printintg in void loop to avoid sending too many commands
  // It will cause a FLOOD Error, and connection will be dropped
}

else {
    
  lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Garage"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Close");
    
  }
}


  

void loop()
{
  Blynk.run();
}

Why are you putting stuff in your setup loop? This way the code will run only once :slight_smile:

Try using the PushData from the examples folder. That will get you underway in a simple way.

Is D7 meant to be an OUTPUT? I would have thought you were after an INPUT.

I tried to put it in loop the app its getting offline every 2 seconds .
can u help me with code plz I just need wen the output D7 is high the LCD show garage is open else garage is closed.
can u show me in the code a small example plz
thank u sir

yes the D7 is an output so wen D7 high I want the LCD shows garage is open else garage is cloed that’s all

Ok, I must have missed the bit in your code that assigns values for D7 to output, it just seems to check the state of D7.

Don’t worry about me, I’m a little slow. I’m so use to using virtual pins to feed in from the app that I forget it’s possible to control the IO pins directly from Blynk.

I had a play with an ESP8266 I have plugged in at the moment, and got this code to do what you want.
The pin numbers are different but it should give you an idea you can use in your code.

On the app side I have the LCD on V0, and a single button on Digital Pin 0 (or GP0).

Press the button led lights, and lcd displays “Door open”, unpress the button and led goes out and lcd display “Door shut”

#define BLYNK_PRINT Serial    
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>


char auth[] = "4664492b01274bab8fa108ce68ade4d5";

WidgetLCD lcd(V0);
int OldState;

void setup()
{
  Serial.begin(115200);
  pinMode(0,OUTPUT);        // There is a led on D0 on my ESP8266
  
  Blynk.begin(auth, "MySSID", "password", IPAddress(10,0,0,8), 8442);
  
  Serial.print("Connecting");
  while (Blynk.connect() == false) {
    // Wait until connected
    Serial.print(".");
    delay(100);
  }
  lcd.clear();
  OldState=false;
}

void loop()
{
  Blynk.run();
  if( digitalRead(0) != OldState )   // Stop hammering the server every loop
  {
    OldState=digitalRead(0);
    lcd.clear();
    if( digitalRead(0) == 0)
    {
      lcd.print(0,0, "Door shut");
    }
    else
    {
      lcd.print(0,0, "Door Open");
    }
  }
}

thank u sir it works really good brother .I do really appreciate ur help.

one more q ,if I wanna add sensor to indicate if the door open or close .

am just gunna change the pinMode (0,INPUT);
and change the digitalRead to analogRead am I right ?

Yes, changing pinMode to an INPUT will work for a sensor.

You should still be able to use the digitalRead to read the sensor, but really it depends on the sensor type. If it’s a switch with appropriate pullups, then digitalRead will do.

If it’s some sort of analogue device, then you may have to use analogRead, but also you’ll need to modify the code as the sensor wont return a simple on/off state.

thank u very much brother u really helped me to solve my problem i do really appreciate ur help .

one small q .
have u tried to use LED in the app as indicator ?
how u use the LED in the app with photon ?

thank u

Hi,

You mean the LED on the board, then yes.

Afarid I don’t have a photon, so wouldn’t know