Problems getting decimal points from average readings
hey guys. im new of , have hit road block. before made heater controller aquarium using uno, ds18b20, , relays. works been while , want make better version.
ive started on new version, time using 2 ds18b20, averaging temps between 2 , using number turn aquarium heaters on , off. know code horrible way accomplish seems kind of working. problem need average temp reading 2 decimal points 2 ds18b20 reading.
temp1: xx.xx f
temp2: xx.xx f
average: xx f
can offer advice?
this have far
ive started on new version, time using 2 ds18b20, averaging temps between 2 , using number turn aquarium heaters on , off. know code horrible way accomplish seems kind of working. problem need average temp reading 2 decimal points 2 ds18b20 reading.
temp1: xx.xx f
temp2: xx.xx f
average: xx f
can offer advice?
this have far
code: [select]
#include <liquidcrystal.h>
#include <onewire.h>
#include <dallastemperature.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
liquidcrystal lcd(rs, en, d4, d5, d6, d7);
#define one_wire_bus 6
#define two_wire_bus 7
onewire onewire(one_wire_bus);
onewire twowire(two_wire_bus);
dallastemperature sensor1(&onewire);
dallastemperature sensor2(&twowire);
void setup()
{
lcd.begin(20, 4);
sensor1.begin();
sensor2.begin();
//temp1
lcd.setcursor (0, 0);
lcd.print ("temp 1:");
lcd.setcursor (14, 0);
lcd.print ("f");
//temp2
lcd.setcursor (0, 1);
lcd.print ("temp 2:");
lcd.setcursor (14, 1);
lcd.print ("f");
//average
lcd.setcursor (0, 2);
lcd.print ("average:");
lcd.setcursor (14, 2);
lcd.print ("f");
}
void loop()
{
sensor1.requesttemperatures();
sensor2.requesttemperatures();
//average temp reading
int = sensor1.gettempfbyindex(0);
int b = sensor2.gettempfbyindex(0);
int c = 2;
int sum = + b;
int average = sum / c;
//temp1 reading
lcd.setcursor(9, 0);
lcd.print(sensor1.gettempfbyindex(0));
//temp2 reading
lcd.setcursor(9, 1);
lcd.print(sensor2.gettempfbyindex(0));
//average of 2 readings
lcd.setcursor (9, 2);
lcd.print (average);
delay(500);
}
quote
int average = sum / c;you've declared average integer. integers don't have fractional parts.
pete
Arduino Forum > Using Arduino > Programming Questions > Problems getting decimal points from average readings
arduino
Comments
Post a Comment