I was looking for a way to print some info to both Serial, Serial1 and a tft. I wanted to place everything in a function and make it readable as well. I wrote this little example script that works, I just wanted to check with the guru's if this is "semantically" correct and if Print is the right class to use.
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Print *CurrentOutput;
void setup()
{
Serial.begin(9600);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
char astring[] = "Look behind you!";
CurrentOutput = &tft;
println_to(CurrentOutput,astring);
CurrentOutput = &Serial;
println_to(CurrentOutput,"you didn't did you?");
}
void loop()
{
}
void println_to(Print *output, char *string)
{
output->println(string);
if (output == &tft)
{
yield(); // Yield refreshes the display of the tft and if not used the display will not our string
}
}