Hey. I was using the Particle to open and close my gate and it was working fine all these days. So i decided to make some changes to the code and publish again via wifi and suddenly now my functions dont appear. I’m using a library liquidcrystal-i2c. When i comment all the lines of code which uses this library the functions appear. But all of this was working fine before i flashed the new firmware.
Please help me get this fixed.
Thanks
This is my code:
// This #include statement was automatically added by the Particle IDE.
#include "LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.h"
LiquidCrystal_I2C *lcd;
const char OLED_Address = 0x27;
const String version = "v1";
const int pinLED1 = D6;
const int pinLED2 = D7;
const int pinReedSensor = A0;
const int pinRelayGND = D3;
const int pinRelaySignal = D2;
int lastSecond = 0;
long lastClosedTime;
long lastOpenedTime;
int isClosed = 0;
bool isCleared = false;
bool isInitiated = false;
bool checkGateOpen = false;
bool showClock = false;
int screenOffDelay = 60000;//time before screen turns off when door is closed
int doorButtonDelay = 1000;
void setup()
{
Serial.begin(9600);
lcd = new LiquidCrystal_I2C(0x27, 16, 2);
initiateDisplay();
//pin initializations
pinMode(pinLED1,OUTPUT);
digitalWrite(pinLED1, LOW);
pinMode(pinLED2,OUTPUT);
digitalWrite(pinLED2, LOW);
pinMode(pinRelayGND,OUTPUT);
digitalWrite(pinRelayGND, LOW);
pinMode(pinRelaySignal,OUTPUT);
digitalWrite(pinRelaySignal, LOW);
pinMode(pinReedSensor,INPUT);
Time.zone(+8);
isClosed = digitalRead(pinReedSensor);
Spark.function("OpenDoor",OperateDoor);
Spark.variable("isClosed", &isClosed, INT);
}
void loop()
{
if(isClosed==0 && digitalRead(pinReedSensor)==1){
lcd->clear();
lcd->print("DOOR CLOSED");
lastClosedTime = millis();
isCleared = false;
isInitiated = false;
}
if(isClosed==1 && digitalRead(pinReedSensor)==0){
showClock = false;
lcd->clear();
lcd->print("DOOR OPEN");
lastOpenedTime = millis();
}
if((lastOpenedTime + (60000 * 5))<millis() && isClosed == 0 && checkGateOpen == false){
Particle.publish("Gate Is Open");
checkGateOpen = true;
}
if((lastClosedTime + 30000)<millis() && !isInitiated && isClosed == 1){
initiateDisplay();
isInitiated = true;
}
if((lastClosedTime + screenOffDelay)<millis() && !isCleared && isClosed == 1){
lcd->clear();
isCleared = true;
checkGateOpen = false;
showClock = true;
}
if(showClock == true && isClosed ==1)
{
if (Time.second() != lastSecond)
{
lcd->clear();
Serial.print(Time.timeStr());
lcd->setCursor(3,0);
lcd->print("TIME CHECK");
lcd->setCursor(0,1);
lcd->print(Time.hour() < 10? " 0" : " ");
lcd->print(Time.hour());
lcd->print(Time.minute() < 10? ":0": ":");
lcd->print(Time.minute());
lcd->print(Time.second() < 10? ":0": ":");
lcd->print(Time.second());
lastSecond = Time.second();
}
}
isClosed = digitalRead(pinReedSensor);
Serial.println(isClosed);
}
int OperateDoor(String args){
int status_code = -1;
if(args == "OPEN" && isClosed==1){
lcd->clear();
lcd->backlight();
lcd->print("OPENING DOOR");
digitalWrite(pinRelaySignal, HIGH);
digitalWrite(pinLED2, HIGH);
delay(doorButtonDelay);
digitalWrite(pinRelaySignal, LOW);
digitalWrite(pinLED2, LOW);
status_code = 1;
}else if(args == "CLOSE" && isClosed == 0){
lcd->clear();
lcd->print("CLOSING DOOR");
digitalWrite(pinRelaySignal, HIGH);
digitalWrite(pinLED2, HIGH);
delay(doorButtonDelay);
digitalWrite(pinRelaySignal, LOW);
digitalWrite(pinLED2, LOW);
status_code = 0;
}
return status_code;
}
int initiateDisplay(){
lcd->init();
lcd->backlight();
lcd->clear();
lcd->setCursor(1,0);
lcd->print("*SMART GARAGE*");
lcd->setCursor(6,1);
lcd->print("V.1");
}