Hi Terry, i´m new with Arduino and my first project is building a temperature-regulator. just i see your project and take parts from your code, but i can not see negative values on my display. have you got an idea, which part i must change? Sorry, i´m newbie and my english is not the best, but i hope, you or everyone can help...
thank you
olli
/*
Basierend auf einen Artikel auf dieser Seite:
http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
den aktuellen Stand findest Du hier:
http://alturl.com/rpods
*/
/*-----( Import needed libraries )-----*/
#include <dht11.h>
#include <Wire.h>
#include <LiquidCrystal.h>
/*-----( Declare objects )-----*/
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //##### DFRobot LCD Keypadshield V1.0
// legt die pins auf dem shield fest
/* begin des tastatur-bereichs */
int lcd_key = 0; // legt nutzung der tasten fest und dann die tasten selber
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
/* ab hier: einlesen der werte der tasten (wiederstands gebilde mit
unterschiedlichen spannungswerten zu jeder taste...*/
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons
since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
/* das wars mit dem tastatur-bereich */
dht11 DHT11;
/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 2
float alarmwert (20);
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Serial.begin(9600);
lcd.begin(16,2); //##### Display Size for DFRobot LCD Keypadshield V1.0
lcd.home ();
lcd.println ("Olliduino "); //##### schreibe willkommensnachricht und springe eine zeile weiter
lcd.setCursor (0,1);
lcd.print ("2011 by olli "); //##### schreibe willkommensnachricht
lcd.home ();
delay(3000);
lcd.clear ();
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
// digitalWrite(13, HIGH);
int chk = DHT11.read(DHT11PIN);
Serial.println("---------------------------"); //der Lesbarkeit erstmal eine Zeile
switch (chk) // teste, ob ueberhaupt daten fliessen
{
case 0: Serial.println("DHT11 ist OK");
Serial.print ("gelieferter Wert: ");
Serial.println ((float)DHT11.temperature,1);
break;
case -1: Serial.println("Checksum error"); break;
case -2: Serial.println("Time out error"); break;
default: Serial.println("Unknown error"); break;
}
Serial.print((float)alarmwert, 1);
Serial.println("C Darunter-Gibt-es-ALARM-Temperatur");
Serial.print((float)DHT11.temperature,1);
Serial.println("C IST-Temperatur");
if ( DHT11.temperature < alarmwert )
{
digitalWrite(13, HIGH);
Serial.println("### !!! Alarm erreicht !!! ###");
lcd.setCursor (15,0); //##### schreibe ab zeichen 14 in zeile 1 (zeile 1 ist gleich 0)
lcd.print("!");
lcd.setCursor (0,1);
}
else
{
digitalWrite(13, LOW);
Serial.println("Alarm nicht erreicht, alles OK");
lcd.setCursor (15,0); //##### schreibe ab zeichen 14 in zeile 1 (zeile 1 ist gleich 0)
lcd.print("*");
lcd.setCursor (0,1);
}
//lcd.noAutoscroll();
lcd.setCursor (0,1);
lcd.print(alarmwert,0);
lcd.print("Cs ");
lcd.print((float)DHT11.temperature,1);
lcd.print("Ci ");
lcd.print((float)DHT11.humidity,1);
lcd.print("%");
digitalWrite(13, LOW);
delay(1000);
// jetzt lesen wir noch die tasten ein und machen was draus
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
lcd.setCursor (0,0);
lcd.print("> ");
break;
}
case btnLEFT:
{
lcd.setCursor (0,0);
lcd.print("<");
break;
}
case btnUP:
{
alarmwert = alarmwert + 1;
lcd.setCursor (0,0);
lcd.print("^");
break;
}
case btnDOWN:
{
alarmwert = alarmwert - 1;
lcd.setCursor (0,0);
lcd.print("v");
break;
}
case btnSELECT:
{
lcd.setCursor (0,0);
lcd.print("*");
break;
}
case btnNONE:
{
lcd.setCursor (0,0);
lcd.print(" ");
break;
}
}
}
/* --(end main loop )-- */