LM35LCD update
This commit is contained in:
parent
9f6c670e78
commit
8c032ca62e
1 changed files with 36 additions and 29 deletions
|
|
@ -12,7 +12,7 @@ LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
|
||||||
// Define how many samples should be collected every $collectDelay miliseconds.
|
// Define how many samples should be collected every $collectDelay miliseconds.
|
||||||
// After sample collection the temperature is beeing calculated and then
|
// After sample collection the temperature is beeing calculated and then
|
||||||
// send to the LCD.
|
// send to the LCD.
|
||||||
int samples = 30;
|
int samples = 16;
|
||||||
|
|
||||||
// Collect delay between each sample.
|
// Collect delay between each sample.
|
||||||
int collectDelay = 2000;
|
int collectDelay = 2000;
|
||||||
|
|
@ -23,7 +23,7 @@ int ledPin = 13;
|
||||||
// The analog input pin where the LM35 is connected to.
|
// The analog input pin where the LM35 is connected to.
|
||||||
int tempPin = 0;
|
int tempPin = 0;
|
||||||
|
|
||||||
// Just some variable initializations
|
// Just some variable initializations.
|
||||||
float tempC = 0;
|
float tempC = 0;
|
||||||
float tempClast = 0;
|
float tempClast = 0;
|
||||||
float tempF = 0;
|
float tempF = 0;
|
||||||
|
|
@ -31,37 +31,21 @@ float tempF = 0;
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(ledPin, OUTPUT);
|
pinMode(ledPin, OUTPUT);
|
||||||
lcd.begin(16, 2);
|
lcd.begin(16, 2);
|
||||||
lcd.print("Temperature:");
|
// Get data for the first time.
|
||||||
lcd.setCursor(0, 1);
|
// Read this to understand the temperature calculation:
|
||||||
|
// http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/
|
||||||
tempC = (5.0 * analogRead(tempPin) * 100.0) / 1024.0;
|
tempC = (5.0 * analogRead(tempPin) * 100.0) / 1024.0;
|
||||||
|
tempClast = tempC;
|
||||||
|
// Celsius to Fahrenheit conversion
|
||||||
tempF = (tempC * 9) / 5 + 32;
|
tempF = (tempC * 9) / 5 + 32;
|
||||||
lcd_print();
|
// Refresh the LCD output
|
||||||
}
|
lcd_refresh();
|
||||||
|
|
||||||
// Prints results to the display
|
|
||||||
void lcd_print() {
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
lcd.print(tempC);
|
|
||||||
lcd.print((char)223);
|
|
||||||
lcd.print("C/");
|
|
||||||
lcd.print(tempF);
|
|
||||||
lcd.print((char)223);
|
|
||||||
lcd.print("F");
|
|
||||||
if(tempClast > tempC) {
|
|
||||||
lcd.print("-");
|
|
||||||
} else if(tempClast < tempC) {
|
|
||||||
lcd.print("+");
|
|
||||||
} else {
|
|
||||||
lcd.print("*");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int i;
|
int i;
|
||||||
tempC = 0;
|
tempC = 0;
|
||||||
for(i = 0; i <= (samples - 1); i++) {
|
for(i = 0; i <= (samples - 1); i++) {
|
||||||
// Read this to understand the temperature calculation:
|
|
||||||
// http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/
|
|
||||||
tempC = tempC + ((5.0 * analogRead(tempPin) * 100.0) / 1024.0);
|
tempC = tempC + ((5.0 * analogRead(tempPin) * 100.0) / 1024.0);
|
||||||
digitalWrite(ledPin, HIGH);
|
digitalWrite(ledPin, HIGH);
|
||||||
delay((collectDelay / 2));
|
delay((collectDelay / 2));
|
||||||
|
|
@ -70,10 +54,33 @@ void loop() {
|
||||||
}
|
}
|
||||||
// Calculate temperature
|
// Calculate temperature
|
||||||
tempC = tempC / (float)samples;
|
tempC = tempC / (float)samples;
|
||||||
// Celsius to Fahrenheit cobversation
|
// Celsius to Fahrenheit conversion.
|
||||||
tempF = (tempC * 9) / 5 + 32;
|
tempF = (tempC * 9) / 5 + 32;
|
||||||
// Print result to the display
|
// Print results to the display.
|
||||||
lcd_print();
|
lcd_refresh();
|
||||||
// Remember current temperature for next run
|
// Remember current temperature for next run.
|
||||||
tempClast = tempC;
|
tempClast = tempC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prints results to the display
|
||||||
|
void lcd_refresh() {
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
lcd.print("Temperature");
|
||||||
|
lcd.print((char)40); // ASCII code 40 = "("
|
||||||
|
if(tempClast > tempC) {
|
||||||
|
lcd.print((char)60); // ASCII code 60 = "<"
|
||||||
|
} else if(tempClast < tempC) {
|
||||||
|
lcd.print((char)62); // ASCII code 61 = ">"
|
||||||
|
} else {
|
||||||
|
lcd.print((char)61); // ASCII code 61 = "="
|
||||||
|
}
|
||||||
|
lcd.print((char)41); // ASCII code 41 = ")"
|
||||||
|
lcd.print((char)58); // ASCII code 58 = ":"
|
||||||
|
lcd.setCursor(0, 1);
|
||||||
|
lcd.print(tempC);
|
||||||
|
lcd.print((char)223); // ASCII code 223 = "°"
|
||||||
|
lcd.print("C/");
|
||||||
|
lcd.print(tempF);
|
||||||
|
lcd.print((char)223); // ASCII code 223 = "°"
|
||||||
|
lcd.print("F");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue