#include"HX711.h"
const int ld_cell=4;
const int ld_sck=5;
HX711 scale;
float weight;
float potPin= A0;
float potVal;
float Angle;
float offsetPot=511.5;
float offsetForce=1050.00;
float Weight;
float Force;
# define LEDPin 6
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
scale.begin(ld_cell,ld_sck);
pinMode(potVal, INPUT);
pinMode(LEDPin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
potReading();
if(Angle>40)
{
digitalWrite(LEDPin, HIGH);
delay(100);
digitalWrite(LEDPin,LOW);
delay(100);
}
//potReading();
//forceReading();
}
void potReading(){
potVal= analogRead(potPin)-offsetPot;
//Serial.println(potVal);
Angle= (135/(1023-511.5)*potVal);
Serial.print("Angle= ");
Serial.print(Angle);
delay(100);
}
void forceReading(){
if(scale.is_ready())
{
long reading=scale.get_units(10)-offsetForce;
Weight= ((2.5/(2100-1050)*reading));
Force= Weight*9.81;
Serial.print(" Weight= " );
Serial.print(Weight);
Serial.print(" Force= " );
Serial.print(Force);
Serial.print(" sensor reading Value= " );
Serial.println(reading);
delay(100);
}
}