#include "Arduino.h"
#include "RA8876_t3.h"
#include "font_Arial.h"
// T4.1
uint8_t dc = 13;
uint8_t cs = 11;
uint8_t rst = 12;
RA8876_t3 tft = RA8876_t3(dc,cs,rst); //(dc, cs, rst)
// Array of Simple RA8876 Basic Colors
// Array of Simple RA8876 Basic Colors
PROGMEM uint16_t myColors[] = {
0x0000, 0xffff, 0xf800, 0xfc10, 0x8000, 0x07e0, 0x87f0, 0x0400,
0x001f, 0x051f, 0x841f, 0x0010, 0xffe0, 0xfff0, 0x8400, 0x07ff,
0x87ff, 0x0410, 0xf81f, 0xfc1f, 0x8010, 0xA145
};
int interations = 0;
int w, h;
int i = 0;
#define BAND_WIDTH 16
#define BAND_HEIGHT 40
#define BAND_START_X 200
#define BAND_START_Y 200
uint16_t pixel_data[5500];
void setup() {
while (!Serial && millis() < 5000) {} //wait for Serial Monitor
//I'm guessing most copies of this display are using external PWM
//backlight control instead of the internal RA8876 PWM.
//Connect a Teensy pin to pin 14 on the display.
//Can use analogWrite() but I suggest you increase the PWM frequency first so it doesn't sing.
// pinMode(BACKLITE, OUTPUT);
// digitalWrite(BACKLITE, HIGH);
tft.begin(20); // 20 is working in 8bit and 16bit mode on T41
tft.graphicMode(true);
tft.setTextCursor(0,0);
tft.setFont(Arial_14);
}
void testGetPixel(uint8_t rotation) {
tft.setRotation(rotation);
Serial.printf("ROTATION: %d\n", rotation);
tft.fillScreen(0xf800);
w = tft.width()-1; h = tft.height()-STATUS_LINE_HEIGHT-1;
tft.printStatusLine(0,myColors[1],myColors[11], "Status Text");
tft.fillRect(0, 0, 400, 200, myColors[8]);
Serial.printf("Rect Color: 0x%x, Pixel Color: 0x%x\n", myColors[8], tft.getPixel(200, 100));
tft.fillRect(tft.width()-400, tft.height()-200, 400, 200, myColors[8]);
Serial.printf("Rect Color: 0x%x, Pixel Color: 0x%x\n", myColors[8], tft.getPixel(200, 100));
//tft.fillRect(tft.width()-400, tft.height()-200, 400, 200, myColors[8]);
//tft.fillRect(tft.width()-400, 0, 400, 200, myColors[8]);
//tft.fillRect(0, tft.height()-200, 400, 200, myColors[8]);
}
void colorBar(uint8_t rotation){
tft.setRotation(rotation);
tft.fillScreen(BLACK);
tft.fillRect(BAND_START_X + BAND_WIDTH * 0, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, RED);
tft.fillRect(BAND_START_X + BAND_WIDTH * 1, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, GREEN);
tft.fillRect(BAND_START_X + BAND_WIDTH * 2, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, BLUE);
tft.fillRect(BAND_START_X + BAND_WIDTH * 3, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, BLACK);
tft.fillRect(BAND_START_X + BAND_WIDTH * 4, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, WHITE);
tft.fillRect(BAND_START_X + BAND_WIDTH * 5, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, YELLOW);
tft.fillRect(BAND_START_X + BAND_WIDTH * 6, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, CYAN);
tft.fillRect(BAND_START_X + BAND_WIDTH * 7, BAND_START_Y, BAND_WIDTH, BAND_HEIGHT, 0xF81F);
tft.printStatusLine(0,myColors[1],myColors[11], "Status Text");
memset(pixel_data, 0, sizeof(pixel_data));
readRect(BAND_START_X, BAND_START_Y, BAND_WIDTH * 8, BAND_HEIGHT, pixel_data);
tft.writeRect(BAND_START_X, BAND_START_Y + BAND_HEIGHT, BAND_WIDTH * 8, BAND_HEIGHT, pixel_data);
}
void readRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *pcolors) {
for(uint16_t j = y; j < (h + y); j++) {
for(uint16_t i = x; i < (w + x); i++) {
*pcolors++ = tft.getPixel(i, j);
}
}
}
//=============================================================================
// Wait for user input
//=============================================================================
void WaitForUserInput() {
Serial.println("Hit Enter to continue");
Serial.flush();
while (Serial.read() == -1)
;
while (Serial.read() != -1)
;
}
void test() {
tft.setTextColor(BLACK);
testGetPixel(0);
WaitForUserInput();
testGetPixel(1);
WaitForUserInput();
testGetPixel(2);
WaitForUserInput();
testGetPixel(3);
WaitForUserInput();
colorBar(0);
WaitForUserInput();
colorBar(1);
WaitForUserInput();
colorBar(2);
WaitForUserInput();
colorBar(3);
WaitForUserInput();
}
void loop() {
test();
}