我正试图在TM1637显示屏上显示温度。我想要显示的变量是“steinhart”。它被声明为一个浮点数,但是当我编译错误时读取:“steinhart'未在此范围内声明”。 Alrighty then,我声明它并在显示屏上显示0。代码由其他代码中的部分组成,因此可能存在差异。另外,如果你可以提供帮助,那就轻松一点,因为编程不是我的强项:)
你觉得我做错了什么?感谢您的任何指导。
#include <Servo.h>
#include <TM1637Display.h>
//---------Servo------------
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val;
//-------Thermistor---------
#define TPIN A1 // which analog pin to connect
#define TRESISTANCE 2500000 // resistance at 25 degrees C
#define TROOM 25 // temp. for nominal resistance
#define NSAMPLES 5 // how many samples to take and average, more takes longer but is more 'smooth'
#define BCOEFF 3980 // The beta coefficient of the thermistor
#define SERIESRESISTOR 100000 // the value of the 'other' resistor
int samples[NSAMPLES];
//---------Display-------------
const int CLK = 3; //Set the CLK pin connection to the display
const int DIO = 2; //Set the DIO pin connection to the display
TM1637Display display(CLK, DIO); //set up the 4-Digit Display.
void setup(void) {
Serial.begin(9600);
myservo.attach(8); // attaches the servo on pin 9 to the servo object
display.setBrightness(0x0a); //set the diplay to maximum brightness
}
void loop(void) {
{uint8_t i;
float average;
for (i=0; i< NSAMPLES; i++) { // take N samples in a row, with a 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 to C
Serial.print("Temperature ");
Serial.print(steinhart);
Serial.println(" *C");
//delay(1000);
//--------Servo Knob----------------
val = analogRead(potpin); // reads the value of the
// potentiometer (value between
// 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with
// the servo (value between 0 and
// 180)
myservo.write(val); // sets the servo position according
// to the scaled value
delay(15);
}
//-----------Display-- -------------
display.showNumberDec(steinhart); //Display the Variable value;
}
这是显示的错误,它引用了最后一行
display.showNumberDec(steinhart); //Display the Variable value;
^
exit status 1
'steinhart' was not declared in this scope