TM1637 to display temperature. Code question
hi there,
i'm trying display temperature on tm1637 display. variable i'm trying display "steinhart". declared float when compile error reads:"steinhart' not declared in scope". alrighty then, declare , displays 0 on display.
my code kind of frankencode there might things not match. ordanized components.
what think i'm doing wrong? thank guidance.
i'm trying display temperature on tm1637 display. variable i'm trying display "steinhart". declared float when compile error reads:"steinhart' not declared in scope". alrighty then, declare , displays 0 on display.
my code kind of frankencode there might things not match. ordanized components.
what think i'm doing wrong? thank guidance.
code: [select]
#include <servo.h>
#include <tm1637display.h>
//---------servo------------
servo myservo; // create servo object control servo
int potpin = 0; // analog pin used connect potentiometer
int val;
//-------thermistor---------
#define tpin a1 // analog pin connect
#define tresistance 2500000 // resistance @ 25 degrees c
#define troom 25 // temp. nominal resistance
#define nsamples 1 // how many samples take , average, more takes longer more 'smooth'
#define bcoeff 3980 // beta coefficient of thermistor
#define seriesresistor 100000 // value of 'other' resistor
int samples[nsamples];
//---------display-------------
const int clk = 3; //set clk pin connection display
const int dio = 2; //set dio pin connection display
tm1637display display(clk, dio); //set 4-digit display.
void setup(void) {
serial.begin(9600);
myservo.attach(8); // attaches servo on pin 9 servo object
display.setbrightness(0x0a); //set diplay maximum brightness
}
void loop(void) {
{uint8_t i;
float average;
(i=0; i< nsamples; i++) { // take n samples in row, slight delay
samples[i] = analogread(tpin);
delay(10);
}
average = 0;
for (i=0; i< nsamples; i++) {
average += samples[i];
}
average /= nsamples;
average = 1023 / average - 1;
average = seriesresistor / average;
float steinhart;
steinhart = average / tresistance; // (r/ro)
steinhart = log(steinhart); // ln(r/ro)
steinhart /= bcoeff; // 1/b * ln(r/ro)
steinhart += 1.0 / (troom + 273.15); // + (1/to)
steinhart = 1.0 / steinhart; // invert
steinhart -= 273.15; // convert c
serial.print("temperature ");
serial.print(steinhart);
serial.println(" *c");
//delay(1000);
//--------servo knob----------------
val = analogread(potpin); // reads value of the
// potentiometer (value between
// 0 , 1023)
val = map(val, 0, 1023, 0, 179); // scale use with
// servo (value between 0 and
// 180)
myservo.write(val); // sets servo position according
// scaled value
delay(15);
}
//-----------display-- -------------
//float steinhart;
display.shownumberdec(steinhart); //display variable value;
}
Arduino Forum > Using Arduino > Project Guidance > TM1637 to display temperature. Code question
arduino
Comments
Post a Comment