#define SENSOR A0
#define LED_COUNTS 10
const int LED[] = {2, 3, 4, 5, 6, 7,8,9,10,11};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while(!Serial);
for(int i = 0; i < LED_COUNTS; ++i) {
pinMode(LED[i], OUTPUT);
}
}
void led_bar(int led_level) {
for(int idx=0; idx < LED_COUNTS; ++idx) {
if(idx < led_level) {
digitalWrite(LED[idx], HIGH);
} else {
digitalWrite(LED[idx], LOW);
}
}
}
float read_temp() {
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
return celsius;
}
void loop() {
// put your main code here, to run repeatedly:
float temp = read_temp();
Serial.print("value is: ");
Serial.println(temp);
int led_level = map(temp,-24, 80, 0, LED_COUNTS);
Serial.print("led level is: ");
Serial.println(led_level);
led_bar(led_level);
delay(200);
}