going to flicker without a sprite or canvas and hope you're using something with a bit of ram like esp32..
#include <Adafruit_GFX.h> // Hardware-specific library
#include <Adafruit_ST7796S.h>
#include <vector>
#define display_CS 10
#define display_RST 8
#define display_DC 9
#define display_MOSI 11
#define display_CLK 13
Adafruit_ST7796S display(display_CS, display_DC, display_MOSI, display_CLK, display_RST);
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
int xPos = 0, xPosPrev = 0;
int n = 0;
int graphHeightPrev = 0;
int border = 20;
int sampleCount = 480 - border;
std::vector<int> v;
int16_t ht = 16, top = 3, line, lines = 15, scroll;
void setup() {
Serial.begin(9600);
Serial.print("Oih !");
display.init(320, 480, 0, 0, ST7796S_BGR); //screen size 74 x 284
display.invertDisplay(1);
display.fillScreen(BLACK);
display.setRotation(1);
display.setTextColor(WHITE);
display.drawLine(12, 60, 12, 260, WHITE);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(20, 40);
display.print("value");
display.setCursor(20, 270);
display.print("value");
display.setCursor(display.width() / 2 - 10, display.height() / 2);
display.print("Buffering..");
}
void loop() {
int sensor = random(200); // for testing
//map the test values into screen cords..
int graphHeight = map(sensor, 1, 200, 60, 260);
//add to the end of the vector..
v.push_back(graphHeight);
//have too many, remove first..
if (v.size() > sampleCount) v.erase(v.begin());
//is it time to draw..
if (v.size() == sampleCount)
{
xPos = 20;
xPosPrev = 20;
graphHeightPrev = 100;
//clear out old graph..
display.fillRect(20, 58, 460, 204, BLACK);
//draw all line in the vector..
for ( int n : v)
{
graphHeight = n;
display.drawLine(xPosPrev, display.height() - graphHeightPrev, xPos, display.height() - graphHeight, WHITE);
graphHeightPrev = graphHeight;
xPosPrev = xPos;
xPos++;
}
}
delay(100);
}
untested sorry..~q