I am trying to create a program to control a variable speed refrigeration compressor based on temperature. The part I am stuck at is on the map function. It should return a value between 0 and 255 but instead 1147 comes out. What is meant to happen is when the temperature is 5 degrees c the compressor is at full speed and when it is at 0 degrees the compressor runs at the slowest speed.
float tempC = sensors.getTempC(deviceAddress); Serial.print("Temp C: "); Serial.print(tempC); compspeed = map(tempC, 1, 5, 0, 255); Serial.println(); Serial.print (compspeed);
and here is the output Temp C: 19.06 1147