I'm working on a project of mine and I'm facing some programing difficulties since i don't have much background. i have made most of the code to work tho, i just need to find a way to stop a delay when a condition is false.
So I'm working with a weight sensor, LCD, and a GSM shield. The weight sensor monitors a variable weight of an object and display that weight on the LCD. When the weight is low the LCD show "REFILL" and the GSM shield sends a text message to a phone number saying "REFILL". When it is refilled the weight sensor go back to monitoring the weight. Thats all great, except when the weight is low the GSM shield keep sending continuous text messages until the weight is back up instead of sending just one text message. so i placed a long delay after the shield sends the first message however now when the weight is back up the weight sensor does not monitor the weight because the arduino would be still in the long delay.
i would like to know what is the best way to interrupt that delay whenever the weight is back up to it's monitoring level.
here is the code i have so far.
#include <LiquidCrystal.h>
#include <hx711.h>
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
LiquidCrystal lcd(12, 11, 5, 4, 9, 8 );
Hx711 scale(A1, A0);
void setup() {
lcd.begin(16, 2);
}
void loop() {
if(scale.getGram() >= -300 && scale.getGram() <= 300){
lcd.setCursor(0, 0);
lcd.print(scale.getGram(), 1);
lcd.print(" g");
lcd.print(" ");
}
else {
lcd.setCursor(0, 0);
lcd.print("REFILL ");
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
char remoteNum[20]="9178214285"; // telephone number to send sms
Serial.println(remoteNum);
// sms text
char txtMsg[200]="REFILL";
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);
// send the message
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
delay(25200000);
}
}