// Reference https://docs.wokwi.com/parts/wokwi-ntc-temperature-sensor

#define sensorPin A0
#define BETA 3950
const int mintemp =-24;
const int maxtemp = 80;

int ledArray[] = {4,5,6,7,8,9,10,11,12,13};

void setup() {
    // initialize LEDs and sensor pin
    Serial.begin(9600);
    for (int pin =0; pin<11; pin=pin+1){
    pinMode(ledArray[pin], OUTPUT);
    digitalWrite(ledArray[pin], LOW);
    }
}

void loop() {
  // Read the sensor value , calculate the temperature, light up the leds
int analogValue = analogRead(A0);
float temp = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
int highled = map(temp, mintemp, maxtemp, 0, 11);
for (int i=10; i>=0; i--){
  if(i < highled){
    digitalWrite(ledArray[i], HIGH);
  }
  else{
    digitalWrite(ledArray[i], LOW);
  }
}
delay(10); // this speeds up the simulation
}