The Serial Plotter is a useful tool, but when you are outside you often do not have access to a computer. But still you can connect your Arduino to a simple TFT display (I used the smallest one I could get: 1.8" = 128x160 pixels).
A small problem shows up: how can you move the content of the screen by one pixel to the left in no time? Well, you just need to store the data you want to display in an array and copy the contents of that array one element to the left. And redrawing is only necessary if the new value differs from the previous one.
The time to shift one sample from right to left is displayed in the bottom right corner. And this is the code:
/*
this version:
drawPixel only if necessary
so time depends on kind of signal at A0
*/
// #define HIGHSPEED
#include <TFT.h>
byte cs = 10;
byte dc = 9;
byte rst = 8;
byte dcfPin = A0;
TFT tft = TFT(cs, dc, rst);
const int setPx = ST7735_WHITE;
const int clrPx = ST7735_BLACK;
byte w, h, count, x1, y1;
byte y[160];
long t1, t2;
void setup() {
Serial.begin(9600);
Serial.println(__FILE__);
tft.begin(); // kostet 2,4 Sekunden!
tft.setRotation(3);
w = tft.width() - 1;
h = tft.height() - 1;
x1 = w - 54; // 9 chars
y1 = h - 8;
tft.fillScreen(clrPx);
tft.drawLine(0, h, w, h, setPx);
t1 = millis();
}
void loop() {
y[w] = analogRead(dcfPin);
for (byte i = 0; i < w; i++)
#ifdef HIGHSPEED
if (abs(y[i + 1] - y[i]) > 1)
#else
if (y[i + 1] != y[i])
#endif
{
tft.drawPixel(i, y[i], clrPx);
y[i] = y[i + 1];
tft.drawPixel(i, y[i], setPx);
}
count++;
if (count > w) {
t2 = millis();
long dt = t2 - t1;
tft.fillRect(x1, y1, 54, 8, clrPx);
tft.setCursor(x1, y1);
tft.print("dt=");
tft.print(dt);
tft.print("ms");
count = 0;
t1 = millis();
}
}That's all.




Comments