Measuring time between two events

I want the board to determine every second is worth 20 cents..

any ideas on how i could you the exact time amount the weight was off the scale in seconds and then multiple that by .20 to find the exact dollar amount?

Not really sure what is being explained in your quote up above.

//global variables area
float seconds;
float cost;
float runningTotal;

boolean timingFlag = false;
unsigned long timingMillis;
unsigned long timeOff;
. . . 

//code area
. . .
if(timingFlag == false && scale.get_units() < -10)
{
  timingFlag = true;
  timingMillis = millis();
}
 
if(timingFlag == true && scale.get_units() >= -10)
{
  Serial.print("Time less than 10 = ");
  timeOff = millis() - timingMillis;
  Serial.println( timeOff );
  timingFlag = false;
}

if(timeOff != 0)
{
  seconds = timeOff / 1000ul;  //milli seconds divided by 1000 is seconds
  cost = seconds * .20;
  Serial.print(“Cost = “);
  Serial.println(cost);
  runningTotal = runningTotal + cost;
  Serial.print(“Running total = “);
  Serial.println(runningTotal);
  timeOff = 0;
}

You could move the cost code into the timing code.

1 Like