Hallo Klaus,
danke für Deine Antwort und für Dein liebes Angebot.
Anbei der Code:
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <Wire.h>
#include "Sodaq_DS3231.h"
#include <SPI.h>
#include <SD.h>
#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9
#define SD_CS 4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
File myFile;
char timeChar[100];
char dateChar[50];
String dateString;
int minuteNow=0;
int minutePrevious=0;
void setup(void) {
Serial.begin(9600);
Wire.begin();
rtc.begin();
tft.initR(INITR_BLACKTAB);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
Serial.println("OK!");
//Überschrift
tft.setRotation(3);
tft.fillScreen(ST7735_BLUE); // Clear display
tft.fillRect(0,0,160,20,ST7735_BLACK);
bmpDraw("LOGO.BMP",0, 5);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(30, 0);
tft.print("Abfahrt");
//Fahrplan
//Block1
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 19);
tft.print("19:15");
tft.setCursor(35, 19);
tft.setTextColor(BLUE, WHITE);
tft.print("ALX841");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 19);
tft.print("Oberstdorf");
tft.setCursor(150, 19);
tft.print("1");
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 29);
tft.print("19:17");
tft.setCursor(35, 29);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3894");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 29);
tft.print("Ulm");
tft.setCursor(150, 29);
tft.print("1");
tft.fillRect(0,39,160,2,ST7735_BLACK);
//Block2
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 41);
tft.print("19:58");
tft.setCursor(35, 41);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3397");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 41);
tft.print("Augsburg");
tft.setCursor(150, 41);
tft.print("3");
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 51);
tft.print("20:05");
tft.setCursor(35, 51);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3294");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 51);
tft.print("Lindau");
tft.setCursor(150, 51);
tft.print("1");
tft.fillRect(0,61,160,2,ST7735_BLACK);
//Block3
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 63);
tft.print("20:15");
tft.setCursor(35, 63);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3394");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 63);
tft.print("Oberstdorf");
tft.setCursor(150, 63);
tft.print("1");
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 73);
tft.print("20:55");
tft.setCursor(35, 73);
tft.setTextColor(BLUE, WHITE);
tft.print("ALX841");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 73);
tft.print("Muenchen");
tft.setCursor(150, 73);
tft.print("1");
tft.fillRect(0,83,160,2,ST7735_BLACK);
//Block4
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 85);
tft.print("21:06");
tft.setCursor(35, 85);
tft.setTextColor(BLUE, WHITE);
tft.print("ALX841");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 85);
tft.print("Lindau");
tft.setCursor(150, 85);
tft.print("1");
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 95);
tft.print("21:10");
tft.setCursor(35, 95);
tft.setTextColor(BLUE, WHITE);
tft.print("RB5767");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 95);
tft.print("Oberstdorf");
tft.setCursor(150, 95);
tft.print("3");
tft.fillRect(0,105,160,2,ST7735_BLACK);
//Block5
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 107);
tft.print("21:56");
tft.setCursor(35, 107);
tft.setTextColor(BLUE, WHITE);
tft.print("RB5767");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 107);
tft.print("Augsburg");
tft.setCursor(150, 107);
tft.print("3");
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 117);
tft.print("21:56");
tft.setCursor(35, 117);
tft.setTextColor(BLUE, WHITE);
tft.print("RB5767");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 117);
tft.print("Augsburg");
tft.setCursor(150, 117);
tft.print("3");
//FahrplanEnde
}
void loop() {
//ConfigStart
DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();
// if (old_ts == 0 || old_ts != ts) {
// old_ts = ts;
minuteNow = now.minute();
if(minuteNow!=minutePrevious)
{
minutePrevious = minuteNow;
String hours = String(now.hour());
if(now.minute()<10)
{
hours = hours+":0"+String(now.minute());
}else
{
hours = hours+":"+String(now.minute());
}
//ConfigEnde
//FahrplanStart
//Überschrift_Uhrzeit
hours.toCharArray(timeChar,100);
tft.setCursor(130, 7);
//tft.setCursor(80, 80);
tft.setTextColor(WHITE, BLACK);
tft.print(timeChar);
}
}
#define BUFFPIXEL 20
void bmpDraw(char *filename, uint8_t x, uint8_t y) {
File bmpFile;
int bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24)
uint32_t bmpImageoffset; // Start of image data in file
uint32_t rowSize; // Not always = bmpWidth; may have padding
uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
boolean goodBmp = false; // Set to true on valid header parse
boolean flip = true; // BMP is stored bottom-to-top
int w, h, row, col;
uint8_t r, g, b;
uint32_t pos = 0, startTime = millis();
if((x >= tft.width()) || (y >= tft.height())) return;
Serial.println();
Serial.print("Loading image '");
Serial.print(filename);
Serial.println(''');
// Open requested file on SD card
if ((bmpFile = SD.open(filename)) == NULL) {
Serial.print("File not found");
return;
}
// Parse BMP header
if(read16(bmpFile) == 0x4D42) { // BMP signature
Serial.print("File size: "); Serial.println(read32(bmpFile));
(void)read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data
Serial.print("Image Offset: "); Serial.println(bmpImageoffset, DEC);
// Read DIB header
Serial.print("Header size: "); Serial.println(read32(bmpFile));
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1) { // # planes -- must be '1'
bmpDepth = read16(bmpFile); // bits per pixel
Serial.print("Bit Depth: "); Serial.println(bmpDepth);
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
goodBmp = true; // Supported BMP format -- proceed!
Serial.print("Image size: ");
Serial.print(bmpWidth);
Serial.print('x');
Serial.println(bmpHeight);
// BMP rows are padded (if needed) to 4-byte boundary
rowSize = (bmpWidth * 3 + 3) & ~3;
// If bmpHeight is negative, image is in top-down order.
// This is not canon but has been observed in the wild.
if(bmpHeight < 0) {
bmpHeight = -bmpHeight;
flip = false;
}
// Crop area to be loaded
w = bmpWidth;
h = bmpHeight;
if((x+w-1) >= tft.width()) w = tft.width() - x;
if((y+h-1) >= tft.height()) h = tft.height() - y;
// Set TFT address window to clipped image bounds
tft.setAddrWindow(x, y, x+w-1, y+h-1);
for (row=0; row<h; row++) { // For each scanline...
// Seek to start of scan line. It might seem labor-
// intensive to be doing this on every line, but this
// method covers a lot of gritty details like cropping
// and scanline padding. Also, the seek only takes
// place if the file position actually needs to change
// (avoids a lot of cluster math in SD library).
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
else // Bitmap is stored top-to-bottom
pos = bmpImageoffset + row * rowSize;
if(bmpFile.position() != pos) { // Need seek?
bmpFile.seek(pos);
buffidx = sizeof(sdbuffer); // Force buffer reload
}
for (col=0; col<w; col++) { // For each pixel...
// Time to read more pixel data?
if (buffidx >= sizeof(sdbuffer)) { // Indeed
bmpFile.read(sdbuffer, sizeof(sdbuffer));
buffidx = 0; // Set index to beginning
}
// Convert pixel from BMP to TFT format, push to display
b = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
tft.pushColor(tft.Color565(r,g,b));
} // end pixel
} // end scanline
Serial.print("Loaded in ");
Serial.print(millis() - startTime);
Serial.println(" ms");
} // end goodBmp
}
}
bmpFile.close();
if(!goodBmp) Serial.println("BMP format not recognized.");
}
// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.
uint16_t read16(File f) {
uint16_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); // MSB
return result;
}
uint32_t read32(File f) {
uint32_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read();
((uint8_t *)&result)[2] = f.read();
((uint8_t *)&result)[3] = f.read(); // MSB
return result;
}
Und der Fahrplan:
Zeit Zugnummer Ziel Gleis
0:12 RE5761 Lindau 1
0:14 RB3396 Oberstdorf 3
4:48 ALX841 Oberstdorf 1
5:10 RB5760 Ulm 2
5:28 RB5760 Memmingen 3
5:32 RE5760 Lindau 1
6:15 RB5763 Augsburg 3
6:17 RB5760 Lindau 1
6:20 RB5762 Oberstdorf 1
6:23 RE5763 Ulm 3
6:27 ALX841 Muenchen 2
6:45 ALX841 Lindau 1
6:56 ALX841 Oberstdorf 1
6:58 ALX796 Muenchen 2
7:02 RE3281 Buchloe 3
7:08 ALX786 Lindau 1
7:12 RB3841 Wangen 1
7:12 ALX796 Oberstdorf 1
7:14 RB5766 Oberstdorf 1
7:46 RB5760 Kempten 3
7:48 RE3282 Lindau 1
7:51 RE3382 Oberstdorf 1
8:16 RE3383 Nuernberg 3
8:21 RB5744 Oberstdorf 1
8:27 RE5739 Lindau 1
8:30 RE3881 Oberstdorf 2
8:42 RB3843 Wangen 1
8:43 RB5762 Oberstaufen 1
8:50 RB5766 Oberstdorf 1
8:57 RE4247 Oberstdorf 3
8:59 ALX841 Muenchen 2
9:11 ALX841 Lindau 1
9:14 ALX841 Oberstdorf 1
9:16 RE3882 Muenchen 3
9:47 RE3284 Lindau 1
9:51 RE3384 Oberstdorf 1
10:16 RE3285 Augsburg 3
10:22 RB5766 Oberstdorf 3
10:27 IC2084 Augsburg 1
10:36 IC2012 Hannover 2
10:51 RE3883 Oberstdorf 1
11:00 ALX841 Muenchen 2
11:06 ALX841 Lindau 1
11:15 ALX841 Oberstdorf 1
11:17 RE3884 Ulm 3
11:47 RE3286 Lindau 1
11:51 RE3386 Oberstdorf 1
12:12 RB5766 Oberstdorf 2
12:16 RE3287 Augsburg 3
12:44 RE3985 Wangen 1
12:51 RB5766 Oberstdorf 1
12:59 ALX841 Muenchen 2
13:06 ALX841 Lindau 1
13:16 RE3892 Ulm 3
13:19 ALX841 Oberstdorf 1
13:24 RB5760 Oberstaufen 1
13:47 RE3288 Lindau 1
13:51 RE3388 Oberstdorf 1
13:56 RB5767 Kempten 3
14:17 RE3289 Augsburg 3
14:45 RE3987 Lindau 1
14:51 RB3887 Oberstdorf 1
15:00 ALX841 Muenchen 2
15:06 ALX841 Lindau 1
15:14 ALX841 Oberstdorf 1
15:17 RE3888 Ulm 3
15:42 IC2085 Oberstdorf 2
15:47 RE3290 Lindau 1
15:51 RE3390 Oberstdorf 1
16:16 RE3391 Augsburg 3
16:20 RB5767 Oberstdorf 2
16:24 IC2085 Oberstdorf 2
16:46 RE3889 Lindau 1
16:51 RB5767 Oberstdorf 1
16:59 ALX841 Muenchen 2
17:06 ALX841 Lindau 1
17:14 ALX841 Oberstdorf 1
17:16 RE3890 Ulm 3
17:40 RE2013 Oberstdorf 2
17:47 RE3292 Lindau 1
17:47 RE3395 Augsburg 3
17:51 RE3392 Oberstdorf 1
17:57 RE2013 Oberstdorf 2
18:16 RE3295 Nuernberg 3
18:22 RB5744 Oberstdorf 1
18:37 RE4248 Stuttgart 2
18:48 RE3891 Lindau 1
18:51 RB3398 Oberstdorf 1
18:57 ALX841 Muenchen 2
19:07 ALX841 Lindau 1
19:15 ALX841 Oberstdorf 1
19:17 RE3894 Ulm 3
19:34 RE5739 Muenchen 2
19:40 RE5765 Ulm 3
19:58 RE3397 Augsburg 3
20:05 RE3294 Lindau 1
20:15 RE3394 Oberstdorf 1
20:55 ALX841 Muenchen 2
21:06 ALX841 Lindau 1
21:10 RB5767 Oberstdorf 3
21:56 RB3299 Augsburg 2
22:11 RE5761 Lindau 1
22:14 RB5767 Oberstdorf 3
23:06 ALX841 Muenchen 2
23:11 ALX841 Lindau 1
23:14 RB5767 Oberstdorf 3
23:56 RB5760 Kempten 2
Es funktioniert allerdings noch nichts uhrzeitgesteuert da ich nicht weiter weis.
Lediglich die einmalige Anzeige funktioniert.
Viele Grüße
Peter