I am currently playing with using a spi tft display for a little project that displays some data.
I'm using the adafruit libraries as
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
I've wired it up for fast display but I find I have to some how erase the previous data displayed before updating it. at first I just did a clear screen with
tft.fillScreen(ST7735_BLACK);
before showing new data (text rotated)
but the blinking was awful
then I tried just drawing a black rectange over the area of the text with
tft.fillRect(0, 30, 200, 60, ST7735_BLACK);
and it's a tiny bit better. There must be a better way. Can't help but wonder if it's the overall structure of the code that is my real issue.
here's the full code
#define cs 10
#define dc 9
#define rst 8 // you can also connect this to the Arduino reset
#define TRIGGER_PIN 7 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 6 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 600 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <NewPing.h>
//#include <stdio.h>
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
void setup(void){
Serial.begin(115200);
tft.initR(INITR_BLACKTAB);
tft.setTextWrap(false); // Allow text to run off right edge
tft.fillScreen(ST7735_BLACK);
tft.setRotation(1);
}
void loop(void) {
int totalPing=0; // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS;
for (int i=0;i<=4;i++){
uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("reading");
Serial.print(i);
Serial.print(":");
Serial.println(uS/US_ROUNDTRIP_IN);
totalPing=totalPing+uS;
delay(30);
}
tft.fillRect(0, 30, 200, 60, ST7735_BLACK);
uS=totalPing/5;
int r;
int f;
int i;
int remainder;
tft.setTextSize(1);
tft.setCursor(0,100);
tft.print("Rangefinder V 0.1");
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(6);
tft.setCursor(0, 30);
r=uS/US_ROUNDTRIP_IN;
Serial.println(r);
remainder=r%12;
f=(r-remainder)/12;
tft.print(f); // Convert ping time to distance in cm and print result (0 = outside set distance range)
tft.print(":");
tft.print(remainder);
//delay(50);
}