//Will be slow when updating all displays without unofficial modifications to Adafruit_GFX and SPI
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
//Change these if needed
uint8_t displayNumber = 6; //Number of displays to update, only 6 are setup below
uint8_t targetFPS = 24; //FPS to target
//Don't change
elapsedMillis oneSecond;
elapsedMillis internalRefresh;
uint32_t looped = 0, internal = 0, fps = 0;
elapsedMicros screenRefresh;
uint8_t displayToUpdate = 0;
uint16_t solidColor = 0;
Adafruit_ST7735 display0 = Adafruit_ST7735(&SPI, 35, 34, 33);
Adafruit_ST7735 display1 = Adafruit_ST7735(&SPI, 36, 34, -1);
Adafruit_ST7735 display2 = Adafruit_ST7735(&SPI, 37, 34, -1);
Adafruit_ST7735 display3 = Adafruit_ST7735(&SPI, 44, 34, -1);
Adafruit_ST7735 display4 = Adafruit_ST7735(&SPI, 45, 34, -1);
Adafruit_ST7735 display5 = Adafruit_ST7735(&SPI, 46, 34, -1);
Adafruit_SPITFT *displays[6] = {
&display0,
&display1,
&display2,
&display3,
&display4,
&display5,
};
const uint16_t canvasWidth = 80;
const uint16_t canvasHeight = 160;
GFXcanvas16 Canvas0 = GFXcanvas16(canvasHeight, canvasWidth);
GFXcanvas16 Canvas1 = GFXcanvas16(canvasHeight, canvasWidth);
GFXcanvas16 Canvas2 = GFXcanvas16(canvasHeight, canvasWidth);
GFXcanvas16 Canvas3 = GFXcanvas16(canvasHeight, canvasWidth);
GFXcanvas16 Canvas4 = GFXcanvas16(canvasHeight, canvasWidth);
GFXcanvas16 Canvas5 = GFXcanvas16(canvasHeight, canvasWidth);
GFXcanvas16 *Canvas[6] = {
&Canvas0,
&Canvas1,
&Canvas2,
&Canvas3,
&Canvas4,
&Canvas5,
};
void setup() {
// put your setup code here, to run once:
delay(1000);
Serial.begin(115200);
for(uint8_t i = 0; i < displayNumber; i++){
Adafruit_ST7735* disp = (Adafruit_ST7735*)displays[i];
// disp->initS(); //Unofficial modification for ST7735S displays
disp->initR(INITR_MINI160x80);
disp->setSPISpeed(79999999);
Canvas[i]->setRotation(1);
Canvas[i]->setTextWrap(0);
}
fps = 0;
looped = 0;
internal = 0;
}
void loop() {
// put your main code here, to run repeatedly:
while(true){
screenUpdate();
if(internalRefresh >= 500){ //Update or read peripherals here, lower refresh rate if needed
internalRefresh -= 500;
internal++;
//Screen color is being changed here
static uint8_t toggle = false;
toggle++;
if(toggle == 3){
solidColor = display0.color565(0,0,0xFF);
toggle = 0;
}
else if(toggle == 2){
solidColor = display0.color565(0,0xFF,0);
}
else if(toggle == 1){
solidColor = display0.color565(0xFF,0,0);
}
}
looped++;
if(oneSecond >= 1000){
oneSecond -= 1000;
Serial.print("FPS: ");
Serial.print(fps);
Serial.print(" Looped: ");
Serial.print(looped);
Serial.print(" Internal: ");
Serial.println(internal);
fps = 0;
looped = 0;
internal = 0;
}
}
}
void screenUpdate(){ //Displays are refreshed here
if(Serial.available()){
targetFPS = (uint8_t)Serial.parseInt();
Serial.print("Setting FPS to ");
Serial.println(targetFPS);
}
if(screenRefresh >= (uint32_t)round((1000000/targetFPS/displayNumber))){ //Display refresh interval based on the number of displays and desired FPS
// screenRefresh -= (uint32_t)round((1000000/targetFPS/displayNumber));
screenRefresh = 0;
drawDisplay(displays[displayToUpdate], Canvas[displayToUpdate]);
displayToUpdate++;
if(displayToUpdate == displayNumber){
displayToUpdate = 0;
fps++;
}
}
}
void drawDisplay(Adafruit_SPITFT *display, GFXcanvas16* canvas){ //Displays are drawn here (only make changes to the canvas here before drawing to your display for increased efficiency)
//Use varibles to keep track of what to draw to the canvas then make the updates here accordingly
canvas->fillScreen(solidColor); //Change canvas color
display->drawRGBBitmap(0,0,canvas->getBuffer(), canvas->height(), canvas->width()); //Draw to display once canvas is ready
}