Skip to content

Instantly share code, notes, and snippets.

@allfake
Last active January 2, 2016 11:39
Show Gist options
  • Save allfake/8297899 to your computer and use it in GitHub Desktop.
Save allfake/8297899 to your computer and use it in GitHub Desktop.
load cell
int minVal = -999;
int threshold = 20;
int calibrate = 300;
int val = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int i = 0;
if (minVal == -999) {
minVal = analogRead(A0);
for(i = 0; i < calibrate; i++) {
int tempVal = analogRead(A0);
minVal = (tempVal + minVal) / 2;
}
}
val = analogRead(A0);
Serial.println(val);
if (val > minVal - (threshold / 2) && val < minVal + (threshold / 2)) {
// minVal = analogRead(A0);
// for(i = 0; i < medium; i++) {
// int tempVal = analogRead(A0);
// minVal = (tempVal + minVal) / 2;
// }
Serial.println(0);
} else {
if (val - minVal > 0) {
Serial.println(val - minVal);
} else {
Serial.println(0);
}
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment