Blink a Temperature
For this setup we are only adding an LM-36 temperature sensor to the previous setup (blink a number). First we take a reading from the sensor and break it up into the Lease Significant Digit LSD and the Most Significant Digit MSB. Each digit is blinked out one a time starting from the MSB and followed by the LSB.
Hookup for Blink a Temperature |
--------------------------- Copy Code Below
// Blinks out the temperature in Centigrade
// Only handles two digit temperatures will not print out negative temperatures
float blinkNum;
byte dl;
byte dm;
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
float voltage = analogRead(A0) * 5.0;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
blinkNum = (int) temperatureC;
//blinkNum = ((analogRead(A0) * 4.88)-500)/10;
dm = (byte) blinkNum /10; // cast float as byte
dl = (byte) blinkNum % 10; // cast float as byte
blinkX(dm);
delay(300);
blinkX(dl);
}
void blinkX(int blinkTimes)
{
if (blinkTimes > 0)
{
for(int x = 0; x < blinkTimes; x++)
{
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
}
}
else // if > 0
{
digitalWrite(13,HIGH); //Zero is a quick blink
delay(50);
digitalWrite(13,LOW);
delay(50);
}
delay(3000);
}
--------------------------- Copy Code Above
TinkerCad Link:
https://www.tinkercad.com/things/49j1ynzkLJ2-blink-out-temperature-from-tmp-36/editel
}
No comments:
Post a Comment