last post (giving up)

I want the code below to only play my wav. files after the time periods have passed but only while weight is being detected. and for the process to restart after the weight has been lifted then put back on once the interval period has passed. The problem I am having is that the timer starts and never resets. the sounds are triggered when weight is detected and when the time is greater than the #define break reminder. but as soon as the script starts the timer is going up 1000 every second even if it returns to 0 when the weight is lifted for longer than the interval it will swiftly shoot up to what it would be if the weight had not been removed. I want the timer to return to 0 then count up from 1000 as it would when you initially start the script.

my code is below. (please don't type explanations as I have tried many and always get lost in what people are saying. please just post corrective code. thanks, it is much appreciated.)

#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 // first break reminder
#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 = 3000; //no weight wait period



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 = millis();  // 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;
    }

 
 
 //intial weight detection sound
 if ( weight >= WEIGHT_THRESHOLD ) {
 
Serial.println("trigger..");
  tmrpcm.play("123.wav");


 }
 


//sound played after 8 seconds of weight detected
if (( weight >= WEIGHT_THRESHOLD) && (StartTime > BREAKREMINDER )){


Serial.println("trigger2..");
  tmrpcm.play("124.wav");

}





  
 }

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

please just post corrective code

Please post payment.

This forum is to get help writing your own code. If you want someone to write your code for you, head over to Gigs and Collaborations. You'll need to negotiate a price with someone willing to write it for you.

“please don't type explanations as I have tried many and always get lost in what people are saying.”

Fascinating.

most people get this before now:

Read "How To Use This Forum"

This is what happens when you do not

there are procedures and expectations. you are not following them.