From 26426d5ad9a7c7e36cfdbb151560838e0226f04e Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 5 Aug 2013 18:18:39 +0200 Subject: [PATCH] PWM temperature change to display backlight --- .../DHT11_DS18B20_temperature.ino | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/DHT11_DS18B20_temperature/DHT11_DS18B20_temperature.ino b/DHT11_DS18B20_temperature/DHT11_DS18B20_temperature.ino index 4ac549f..c5fb8da 100644 --- a/DHT11_DS18B20_temperature/DHT11_DS18B20_temperature.ino +++ b/DHT11_DS18B20_temperature/DHT11_DS18B20_temperature.ino @@ -79,6 +79,7 @@ DallasTemperature sensors(&oneWire); // pin 3 - LCD reset (RST) Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); +#define Backlight_Pin 9 void setup() { @@ -98,6 +99,12 @@ void setup() // for the best viewing! display.setContrast(50); + pinMode(Backlight_Pin, OUTPUT); + + pinMode(0, INPUT); + Serial.print("Backlight "); + Serial.println(analogRead(0)); + display.clearDisplay(); display.setTextSize(1); display.setTextColor(BLACK); @@ -209,10 +216,22 @@ void loop() // refresh LCD display.display(); + // pulse display backlight + int backlight = 0; + + float old_temp = temp[(temp_pos + TEMP_SIZE - 1) % TEMP_SIZE]; + if ( ds18b20_temperature < old_temp ) { + backlight = 32; + } else if ( ds18b20_temperature > old_temp ) { + backlight = 255; + } + analogWrite(Backlight_Pin, backlight); + + delay(2000); + // move slot in circular bugger if ( ++temp_pos > TEMP_SIZE ) temp_pos = 0; - delay(2000); } // // END OF FILE -- 2.20.1