/*
QUICK README:
The following code is a modification done by Ross Clark of the code created by Nathan Seidle from Sparkfun Electronics. If you meet him you 
must buy him a beer under the rules of the Beerware licence. 
This example code also uses bogde's excellent library for the HX711: https://github.com/bogde/HX711
bogde's library is released under a GNU GENERAL PUBLIC LICENSE

If this version does not work you can download the files from the https://www.rehabtools.org  website and open in Arduino on your computer.

*/

#include "HX711.h"

// This assumes the following connections have been made
// Amplifier Board DAT = Arduino digital pin 3
// Amplifier Board CLK = Arduino digital pin 2

HX711 scale(3, 2);    // parameter "gain" is ommited; the default value 128 is used by the library
float force = 0;
#define calibration_factor -7050.0

// Generally, you should use "unsigned long" for variables that hold time
// The value can quickly become too large for an integer to store - not in this case but its good practice
unsigned long previousMillis = 0;        // will store last time the serial output was updated

// constants won't change :
const long interval = 1;           // interval at which to check for changes in the load cell data (milliseconds). 1 is fine


void setup() {
  Serial.begin(57600);
  scale.set_scale(calibration_factor); //Calibration factor (defined above) is very important for the accuracy of your data. 
  //The number in this code is arbitrary and will not be directly applicable to your load cell, but will likley put you in the ballpark
  //You can then experiment with the Sparkfun code or the additional software from my site (rehabtools.org)
  scale.tare();  //Zero the load cell - this is important to remove factors such as drift or when starting with something on the load cell
  // you don't want to include in the weight. 

  }

void loop() {
  force =  scale.get_units()*0.453592; //This multiples the original value by 0.454 to convert from lbs to kg. 
 
  //The following section is a very good piece of code to use when collecting data. It waits for a set interval (set above) then runs the subsequent code. 
  unsigned long currentMillis = millis(); 
  if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
   Serial.println(force); //This prints the force value from the load cell to the serial port. You can then use this data for your own programs
   // or extract it using the examples on my site (rehabtools.org).
  }
}
