Hello,
I have read this post(http://arduino.cc/forum/index.php/topic,95007.0.html and it's almost exactly what I was looking for a long time.
From this it is also the following sketch:
#include <Wire.h>
#include <LiquidCrystal.h>
#define DS1307_ADDRESS 0x68 // This is the I2C address
// SainSmart LCD 16x2
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
// Arduino Mega 2560
const int Blue1Pin = 2;
const int Blue2Pin = 3;
const int White3Pin = 11;
const int White4Pin = 12;
const int Night1Pin = 13;
const unsigned long HOUR = 60 * 60;
const unsigned long MINUTE = 60;
const int TARGET_BRIGHTNESS = (255 * 3) / 4; // Target brightness is 3/4 of full
void setup()
{
lcd.begin(16, 2);
Wire.begin();
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("***");
lcd.setCursor(4,0);
///// Get time from RTC into RTCHour, RTCMinute, RTCSecond
// Set the register pointer to 0 (Second)
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write((byte)0);
Wire.endTransmission();
// Read Second, Minute, and Hour
Wire.requestFrom(DS1307_ADDRESS, 3);
int RTCSecond = bcdToDec(Wire.read());
int RTCMinute = bcdToDec(Wire.read());
int RTCHour = bcdToDec(Wire.read() & 0b111111); //24 hour time
// write Time to LCD XX:XX:XX
if(RTCHour < 10) {
lcd.print("0");
}
lcd.print(RTCHour);
lcd.print(":");
if(RTCMinute < 10) {
lcd.print("0");
}
lcd.print(RTCMinute);
lcd.print(":");
if(RTCSecond < 10) {
lcd.print("0");
}
lcd.print(RTCSecond);
lcd.setCursor(13,0);
lcd.print("***");
unsigned long time = RTCHour * HOUR + RTCMinute * MINUTE + RTCSecond; // Time in seconds
// write value within the timeframe to PWM
analogWrite(Blue1Pin, brightness(time, 7*HOUR, 19*HOUR));
analogWrite(Blue2Pin, brightness(time, 7*HOUR+30*MINUTE, 19*HOUR+30*MINUTE));
analogWrite(White3Pin, brightness(time, 8*HOUR+30*MINUTE, 16*HOUR+30*MINUTE));
analogWrite(White4Pin, brightness(time, 9*HOUR+30*MINUTE, 17*HOUR+30*MINUTE));
analogWrite(Night1Pin, TARGET_BRIGHTNESS);
// write actual value in % to LCD (max. 255 = 100%)
lcd.setCursor(0,1); //White3Pin
if(((brightness(time, 8*HOUR+30*MINUTE, 16*HOUR+30*MINUTE))*100/255) < 10) {
lcd.print("0");
}
lcd.print((brightness(time, 8*HOUR+30*MINUTE, 16*HOUR+30*MINUTE))*100/255);
lcd.print("%");
lcd.setCursor(4,1); //Blue1Pin
if(((brightness(time, 7*HOUR, 19*HOUR))*100/255) < 10) {
lcd.print("0");
}
lcd.print((brightness(time, 7*HOUR, 19*HOUR))*100/255);
lcd.print("%");
lcd.setCursor(8,1); //Blue2Pin
if(((brightness(time, 7*HOUR+30*MINUTE, 19*HOUR+30*MINUTE))*100/255) < 10) {
lcd.print("0");
}
lcd.print((brightness(time, 7*HOUR+30*MINUTE, 19*HOUR+30*MINUTE))*100/255);
lcd.print("%");
lcd.setCursor(12,1); //White4Pin
if(((brightness(time, 9*HOUR+30*MINUTE, 17*HOUR+30*MINUTE))*100/255) < 10) {
lcd.print("0");
}
lcd.print((brightness(time, 9*HOUR+30*MINUTE, 17*HOUR+30*MINUTE))*100/255);
lcd.print("%");
delay(1000);
}
byte brightness(unsigned long time, unsigned long fadeUpStart, unsigned long fadeDownStart)
{
// Mid day, light is at maximum brightness
if (time >= fadeUpStart + HOUR && time <= fadeDownStart)
return TARGET_BRIGHTNESS;
// Dawn: fade up the light
if (time >= fadeUpStart && time <= fadeUpStart + HOUR) // Fading up
{
unsigned long seconds = time - fadeUpStart; // Number of seconds into the fade time
return TARGET_BRIGHTNESS * seconds / (HOUR); // Fade up based on portion of interval completed.
}
// Evening: Fade down the light
if (time >= fadeDownStart && time <= fadeDownStart + HOUR) // Fading down
{
unsigned long seconds = (fadeDownStart + (HOUR)) - time; // Number of seconds remaining in the fade time
return TARGET_BRIGHTNESS * seconds / (HOUR); // Fade down based on portion of interval left.
}
// The remaining times are night and the lights is off
return 0; // Shouldn't get here
}
I'm from Germany and unfortunately my English is really bad. So I write it with a translation program. I would like to display the light levels (brightness) in (%) on my display. But I have another display, as will be controlled in the sketch. I've rewritten the first sketch, so I light levels (brightness) in (%) in the serial monitor displays and get it working.
Unfortunately I can not get the commands in exchange Serial.print lcd.print and everything works.
I have the following graphic display http://tronixstuff.wordpress.com/2011/03/12/the-dfrobot-lcd4884-lcd-shield/ and I'm glad that I get message with a RTC (DS1307) the date and time .
Looks like this:
#include <Wire.h>
#include <RTClib.h>
#include "LCD4884.h"y
RTC_DS1307 RTC;
DateTime now;
const char LOGFORMAT[] = "%02u.%02u.%04u %02u:%02u:%02u";
void setup(){
//Serial.begin(9600);
Wire.begin();
RTC.begin();
lcd.LCD_init();
lcd.LCD_clear();
lcd.backlight(ON);
}
void loop() {
lcd.LCD_write_string(0, 0,"LED-Steuerung", MENU_HIGHLIGHT);
lcd.LCD_write_string(8, 2,"c by Knippi", MENU_NORMAL);
now=RTC.now();
static char dataString[0];
sprintf(dataString, LOGFORMAT, now.day(), now.month(), now.year(),now.hour(),now.minute(),now.second() );
lcd.LCD_write_string(10, 4,dataString, MENU_NORMAL);
}
I've tried a lot and I think it must be in this part of the sketch to be installed, but how and what values???
static char dataString[0];
sprintf(dataString, LOGFORMAT, now.day(), now.month(), now.year(),now.hour(),now.minute(),now.second() );
lcd.LCD_write_string(10, 4,dataString, MENU_NORMAL);
I hope it has an idea.
Thank you ever.
Jens