Hey guys, I didn’t know if this was the correct category but I was just looking for a little guidance on how I should start with this coding. Basically, I have been making a signal that triggers a text message whenever there is force on a load cell. Right now, I have it so it triggers a SMS message whenever there is over 5 lbs read on the scale. In order for me to make it more realistic for my project idea, I am going to have to make it so it triggers the message when the scale is reading x > weight for y = however many seconds. I saw there is a timer library SPARKINTERVALTIMER that I’m sure I could use to keep the time. I am just not sure how I could combine these two values to set off my flag when the conditions are met.
Here is my code (any recommendations on how I could make it better just let me know):
// This #include statement was automatically added by the Particle IDE.
#include "HX711ADC.h"
// This #include statement was automatically added by the Particle IDE.
#include "Ubidots.h"
/****************************************
* Define Constants
****************************************/
#define DOUT D0
#define CLK D1
#define " // My Ubidots TOKEN
Ubidots ubidots(TOKEN);
HX711ADC scale(DOUT, CLK);
float calibration_factor = -7050; //from sparkfun example (May be incorrect)
/****************************************
* Main Functions
****************************************/
void setup() {
Serial.begin(9600);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
Serial.println("Readings:");
}
void loop() {
float weight = scale.get_units();
Serial.print("Reading: ");
Serial.print(weight, 1);
Serial.print(" lbs");
Serial.println();
if (weight > 5) {
int flag = 1;
ubidots.add("flag", flag);
ubidots.sendAll();
delay(5000);
flag = 0;
ubidots.add("flag", flag);
ubidots.sendAll();
delay(5000)
}
}