/*
* Ucglib_HelloWorld_8x13_Rainbow_Colors
*
* Tested on NodeMCU v2 and Arduino ProMini using
* https://github.com/spapadim/ucglib as of
* commit 032641d12d17283523767a7e8bacc105e474435e
*/
#include <SPI.h>
#include "Ucglib.h"
#if defined(ESP8266)
#define CS 15
#define DC 5
#define RST 16
#elif defined(__AVR__)
#define CS 10
#define DC 9
#define RST 8
#else
#error Tested architectures are ESP8266 and AVR
#endif
/*
* The following works with http://www.banggood.com/1_8-Inch-Serial-SPI-TFT-LCD-Display-Module-With-Power-IC-SD-Socket-p-909802.html
* in which "Normally, the chip is Samsung ST7735."
*/
Ucglib_ST7735_18x128x160_HWSPI ucg(/*cd=*/ DC , /*cs=*/ CS, /*reset=*/ RST);
// http://colrd.com/palette/23813/?download=css
struct color {
uint8_t red;
uint8_t green;
uint8_t blue;
};
struct color rainbow[] = {
{209, 0, 0},
{255, 102, 34},
{255, 218, 33},
{51, 221, 0},
{17, 51, 204},
{34, 0, 102},
{51, 0, 68}
};
void setup(void)
{
Serial.begin(115200);
Serial.print("Sizeof color: ");
Serial.println(sizeof (color));
Serial.print("Sizeof rainbow: ");
Serial.println(sizeof (rainbow));
Serial.println("Initializing display");
ucg.begin(UCG_FONT_MODE_SOLID);
ucg.clearScreen();
}
void loop(void)
{
int row, col;
int height = 13;
char *digits = "01234567890123456789";
ucg.setFontPosTop();
ucg.setRotate270();
ucg.setFont(ucg_font_8x13_mf);
Serial.println("Starting to paint screen");
col = 0;
ucg.setColor(1, 0, 0, 0); // Black background
for (row = 0; row < sizeof(rainbow) / sizeof(color); row++) {
ucg.setPrintPos(col, height * row);
ucg.setColor(0, rainbow[row].red, rainbow[row].green, rainbow[row].blue);
ucg.print(digits);
}
ucg.setPrintPos(col, height * row++);
ucg.setColor(0, 255, 255, 255);
ucg.print(digits);
ucg.setPrintPos(col, height * row);
ucg.setColor(0, 0, 0, 0); // White background
ucg.setColor(1, 255, 255, 255);
ucg.print(digits);
delay(1000);
Serial.println("Clearing screen");
ucg.clearScreen();
}
A generic 240x320 ILI9341/XPT2046 is supposed to show up any day now, will see what luck I have with that and the Adafruit_GFX port.