Commit 32e0a498 authored by Jason Williams's avatar Jason Williams

Removing unnecessary variables and reusing existing ones where appropriate

parent 30f041d1
......@@ -155,25 +155,24 @@ void loop() {
unsigned long elapsed_temperature = millis() - sent_temperature;
if(elapsed_temperature >= 30000) {
DallasTemp.requestTemperatures();
char ambtempstr[6], frztempstr[6];
sprintf(ambtempstr, "%.1f", DallasTemp.getTempC(ambient));
sprintf(frztempstr, "%.1f", DallasTemp.getTempC(freezer));
client.publish(topic_ambienttemp, ambtempstr);
client.publish(topic_freezertemp, frztempstr);
char tempstr[6];
sprintf(tempstr, "%.1f", DallasTemp.getTempC(ambient));
client.publish(topic_ambienttemp, tempstr);
Serial.print("[Temperature] Ambient temperature is ");
Serial.print(ambtempstr);
Serial.print(tempstr);
Serial.println(" degrees");
sprintf(tempstr, "%.1f", DallasTemp.getTempC(freezer));
client.publish(topic_freezertemp, tempstr);
Serial.print("[Temperature] Freezer temperature is ");
Serial.print(frztempstr);
Serial.print(tempstr);
Serial.println(" degrees");
// Clear the triggers
digitalWrite(pin_trigger1, LOW);
digitalWrite(pin_trigger2, LOW);
delayMicroseconds(2);
char dist1str[4], dist2str[4];
char diststr[4];
// Take a reading on sensor 1
digitalWrite(pin_trigger1, HIGH);
......@@ -183,8 +182,8 @@ void loop() {
distance = duration*0.017;
// Publish sensor 1 reading
sprintf(dist1str, "%d", distance);
client.publish(topic_spot1, dist1str);
sprintf(diststr, "%d", distance);
client.publish(topic_spot1, diststr);
Serial.print("[Distance] Sensor 1 at ");
Serial.print(distance);
Serial.println("cm");
......@@ -197,8 +196,8 @@ void loop() {
distance = duration*0.017;
// Publish sensor 2 reading
sprintf(dist2str, "%d", distance);
client.publish(topic_spot2, dist2str);
sprintf(diststr, "%d", distance);
client.publish(topic_spot2, diststr);
Serial.print("[Distance] Sensor 2 at ");
Serial.print(distance);
Serial.println("cm");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment