Hey Guys. My project involves wiring a load cell to a chair using an Arduino as well as a speaker and sd to store and play audio files. The purpose of this is that when I sit down my chair will say welcome and then time how long I have been sitting there for then after a period of time sitting it will remind me to take a break. The timer will reset once i have left the seat for a short period and the process will start again once I sit back down. I already have everything wired up correctly buts its the code I am having trouble with. Im new and I know most people on here are wizards at this so I would like advice or examples on how I should go about this. (I've probably annoyed lots of people with this already but I think now that they are giving me perfect solutions to the wrong problem maybe because I have poorly explained.)
here's my current code if you want to look at it.
#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
#define WAIT_FOR_WEIGHT 0
#define WAIT_FIRST_SOUND 1
#define WAIT_SEC_SOUND 2
#define RESET_WAIT 3
TMRpcm tmrpcm;
HX711 scale;
float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
float weight;
int state = WAIT_FOR_WEIGHT;
unsigned long StartTime =0; //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);**
SetupSound();
}
void loop() {
weight = scale.get_units();
** weight = weight;**
** if ( weight < 12000 ) {**
** weight = 0;**
** }**
if (state == WAIT_FOR_WEIGHT )
** {**
** // Timer is not running. Check for condition to start the timer.**
** if (weight > WEIGHT_THRESHOLD)**
** StartTime = millis(); // Start the timer**
** state = WAIT_FIRST_SOUND;**
** Serial.println (StartTime);**
** }**
** if (millis() - StartTime >= BREAKREMINDER)**
** {**
** // Timer was running and has expired**
** Serial.println("trigger..");**
** tmrpcm.play("123.wav");**
** StartTime = millis();**
state = WAIT_SEC_SOUND;
** // DO YOUR TIMER EXPIRED STUFF HERE**
** }**
if(state == WAIT_SEC_SOUND){
** if( millis() - StartTime > BREAKREMINDERS){**
** Serial.println("trigger2..");**
** tmrpcm.play("123.wav");**
** StartTime = millis();**
** state = RESET_WAIT;**
** }**
}
if(millis() - StartTime > Interval){
** state = WAIT_FOR_WEIGHT;**
}
}