here my code. sorry about the structure. im new
#include <HX711.h>
#include <SD.h>
#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#define BREAKREMINDERS 15000//Second break reminder
#define BREAKREMINDERT 30000// Third break reminder
#define BREAKREMINDER 8000
#define WEIGHT_THRESHOLD 4 //Threshold to count for person sitting
#define SD_ChipSelectPin 4 // SD CARD IN PIN 4
#define SPEAKER 9 // SPEAKER OUTPUT IN PIN 9
#define DOUT 3
#define CLK 2
TMRpcm tmrpcm;
HX711 scale;
float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
float weight;
unsigned long StartTime; //Sitting timer
const unsigned long Interval = 5000;
void SetupSound() {
// put your setup code here, to run once:
tmrpcm.speakerPin = SPEAKER;
tmrpcm.CSPin = SD_ChipSelectPin;
if (!SD.begin(SD_ChipSelectPin))
{
Serial.println("failed to read card..");
return;
}
tmrpcm.setVolume(5);
Serial.println("Card read success..");
}
void setup() {
Serial.begin(9600);
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.begin(DOUT, CLK);
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
StartTime = 0; // Timer is not running
SetupSound();
}
void loop() {
if (StartTime == 0)
{
// Timer is not running. Check for condition to start the timer.
if (weight > WEIGHT_THRESHOLD)
StartTime = millis(); // Start the timer
}
else // Timer is running
{
if (millis() - StartTime >= Interval)
{
// Timer was running and has expired
StartTime = 0; // Stop the timer
// DO YOUR TIMER EXPIRED STUFF HERE
}
}
Serial.println(StartTime);
weight = scale.get_units();
weight = weight;
if ( weight < 12000 ) {
weight = 0;
}
if ( weight >= WEIGHT_THRESHOLD ) {
Serial.println("trigger..");
tmrpcm.play("123.wav");
}
if (( weight >= WEIGHT_THRESHOLD) && (StartTime > BREAKREMINDER )){
Serial.println("trigger2..");
tmrpcm.play("124.wav");
}
}