Skip to content

Instantly share code, notes, and snippets.

@bwhitman
Last active August 29, 2015 14:24
Show Gist options
  • Save bwhitman/f742b0ec2afb48fd91ba to your computer and use it in GitHub Desktop.
Save bwhitman/f742b0ec2afb48fd91ba to your computer and use it in GitHub Desktop.
Bread Detector loop
void loop() {
uint sensorValue = read_analog();
delay(10);
if (sensorValue > 0) {
float voltage = sensorValue / 1023.0;
float temp = getTemp();
if (temp < 1) temp = 0; // bad connection or something
temp_average = temp_average + temp;
sensor_average = sensor_average + voltage;
readings = readings + 1;
if (millis() > millis_start + MS_CYCLE ) {
float temp_average_print = temp_average / readings;
float sensor_average_print = sensor_average / readings;
// Convert sensor value to inches
float inches = pow(sensor_average_print, -1.365) * 0.9652;
postToPhant();
millis_start = millis();
readings = 0;
inch_average = 0;
temp_average = 0;
sensor_average = 0;
}
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment