Hallo zusammen,
die Uhr habe ich am laufen (bisher mit folgendem Code)
#include <DS1307.h>
#include <ITDB32_Touch.h>
#include <ITDB02_Graph16_1.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
ITDB02 myGLCD(38,39,40,41,ITDB32WC);
ITDB32_Touch myTouch(6,5,4,3,2);
DS1307 rtc(20, 21); // Init DS1307 // SDA pin -> Arduino Mega Digital 20, SCL pin -> Arduino Mega Digital 21
int x, y, xo, zo, twt, stst;
Time t;
word yr;
int swz, wsz, tval;
int val_1;
// ---------------------------------------------------------------------------------------------------------------------
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
delay(50);
}
void loop()
{ // void loop Anfang
run:
t = rtc.getTime(); // Uhr
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(225, 225, 225);
myGLCD.setFont(BigFont);
myGLCD.print(".", 40, 30);
myGLCD.print(rtc.getTimeStr(), 8, 10); // Zeitdaten
myGLCD.print(rtc.getDateStr(FORMAT_SHORT), 8, 50); // 232, 10) // 312, 10); // Datum
myGLCD.print(rtc.getDOWStr(FORMAT_SHORT), 8, 30); // 190, 10) //286, 10); // Wochentag
}
habe dann versucht ein externes EEPROM über I2C ansprechen
#include <EEPROM.h>
#include <Wire.h>
#define eeprom 0x50
void setup()
....
EEPROM.write(0, stBegin[8]);
...
sobald ich in void setup die Zeile Wire.begin(); mit einfüge, zeigt mit die Uhr seltsame Zeiten an (27:85:85) als Wochentag xx und beim Datum
85.85.@5, die Uhr steht, das EEPROM lässt sich aber mit entsprechenden Codezeilen (Wire.send) etc. ansprechen.
mit folgendem Code läufts:
#include <ITDB32_Touch.h>
#include <ITDB02_Graph16_1.h>
#include <EEPROM.h>
#include <Wire.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
ITDB02 myGLCD(38,39,40,41,ITDB32WC);
ITDB32_Touch myTouch(6,5,4,3,2);
const byte EEPROM_ID = 0x50;
const byte DS1307_CTRL_ID = 0x68;
const byte NumberOfFields = 7;
int Second, Minute, Hour, WDay, Day, Month, Year, x;
unsigned int address = 0;
// ---------------------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600);
Wire.begin();
schreibeEEPROM(EEPROM_ID, address, strchar);
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setColor(200, 200,200);
myGLCD.setFont(BigFont);
myGLCD.print(":", 30, 10);
myGLCD.print(":", 70, 10);
//myGLCD.print(".", 30, 30);
myGLCD.print(".", 30, 50);
myGLCD.print(".", 70, 50);
char value[8]="*1050#";
char strchar[8]="#1050*";
}
// ==============================( DRAW Schleifen )==========================
// ===========================( Beginn Hauptschleife ) ======================
void schreibeEEPROM(int I2CEEPROMAdresse, unsigned int address, char strchar[8])
{
Wire.beginTransmission(I2CEEPROMAdresse);
Wire.send(0x00);
Wire.send(strchar);
Wire.endTransmission();
delay(5);
}
char leseEEPROM(int I2CEEPROMAdresse, unsigned int address)
{
Wire.beginTransmission(I2CEEPROMAdresse);
Wire.send(0x00);
Wire.endTransmission();
Wire.requestFrom(I2CEEPROMAdresse, 1);
return strchar[8];
delay(5);
myGLCD.print(strchar, CENTER, 20);
}
void loop() // void loop Anfang
{
Wire.beginTransmission(DS1307_CTRL_ID);
Wire.send(0x00);
Wire.endTransmission();
Wire.requestFrom(DS1307_CTRL_ID, NumberOfFields);
Second = bcd2dec(Wire.receive() & 0x7f);
Minute = bcd2dec(Wire.receive() );
Hour = bcd2dec(Wire.receive() & 0x3f);
WDay = bcd2dec(Wire.receive() );
Day = bcd2dec(Wire.receive() );
Month = bcd2dec(Wire.receive() );
Year = bcd2dec(Wire.receive() );
Year = Year + 2000;
Serial.print(address);
Serial.print("\t");
Serial.print(strchar);
Serial.println();
digitalClockDisplay();
delay(990);
}
// -------------------------------------------------------------------
byte bcd2dec(byte num)
{
return ((num/16*10) + (num%16));
return (WDay);
}
void digitalClockDisplay()
{
myGLCD.setBackColor(225, 225, 225);
myGLCD.setColor(0, 0, 0);
myGLCD.setFont(BigFont);
if (Hour<10)
{
myGLCD.print("0", 0, 10);
myGLCD.printNumI(Hour, 16, 10);
}
else
{
myGLCD.printNumI(Hour, 0, 10);
}
if (Minute<10)
{
myGLCD.print("0", 40, 10);
myGLCD.printNumI(Minute, 56, 10);
}
else
{
myGLCD.printNumI(Minute, 40, 10);
}
if (Second<10)
{
myGLCD.print("0", 80, 10);
myGLCD.printNumI(Second, 96, 10);
}
else
{
myGLCD.printNumI(Second, 80, 10);
}
if (WDay==1)
{
myGLCD.print("Mo.", 0, 30);
}
if (WDay==2)
{
myGLCD.print("Di.", 0, 30);
}
if (WDay==3)
{
myGLCD.print("Mi.", 0, 30);
}
if (WDay==4)
{
myGLCD.print("Do.", 0, 30);
}
if (WDay==5)
{
myGLCD.print("Fr.", 0, 30);
}
if (WDay==6)
{
myGLCD.print("Sa.", 0, 30);
}
if (WDay==7)
{
myGLCD.print("So.", 0, 30);
}
if(Day<10)
{
myGLCD.print("0", 0, 50);
myGLCD.printNumI(Day, 16, 50);
}
else
{
myGLCD.printNumI(Day, 0, 50);
}
if(Month<10)
{
myGLCD.print("0", 40, 50);
myGLCD.printNumI(Month, 56, 50);
}
else
{
myGLCD.printNumI(Month, 40, 50);
}
myGLCD.printNumI(Year, 80, 50);
myGLCD.print(strchar, CENTER, 20);
}
ist es möglich, das ganze einfacher zu gestalten, bzw. zumindest die Jahresanzeige auf zwei Stellen zu verkürzen (12 statt 2012) ?