Hello, I'm trying to create an oscilloscope with the help of my Arduino Uno and the official Arduino TFT LCD screen: http://arduino.cc/en/Main/GTFT
The problem I'm having and can't seem fix is that everytime I re-draw the grid and the signal the screen is flickering, I've tried to fix it by adding a delay at the end of the loop but it's the same flickering but with slower intervals as expected.
I've also tried to not re-draw the grid every single loop and just removing the previous signal values by re-writing the same signal with the same stroke color as the background, but then the problem is that I overwrite the grid and it eventually gets removed by the signal moving back and forth over the screen.
Do you guys have any solutions of how I might be able to fix this problem?
Here's a video of how it looks: - YouTube
#include <SPI.h>
#include <TFT.h>
#define cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(cs, dc, rst);
int sample[160];
void setup()
{
pinMode(A0, INPUT);
TFTscreen.begin();
TFTscreen.background(255,255,255); // set background to white
TFTscreen.stroke(0,0,0); // set stroke color to black
}
void loop()
{
drawGrid();
for(int i = 0;i < 160; i++)
{
sample[i] = analogRead(A0);
}
for(int i = 0; i < 160; i+=2)
{
TFTscreen.line(i, (93 - (sample[i] / 12)), (i + 1), (93 - (sample[i + 1] / 12))); //Dividing by 12 to fit signal on display
TFTscreen.line(i, (94 - (sample[i] / 12)), (i + 1), (94 - (sample[i + 1] / 12))); // 3 lines for thicker line on the display
TFTscreen.line(i, (95 - (sample[i] / 12)), (i + 1), (95 - (sample[i + 1] / 12)));
}
}
void drawGrid()
{
TFTscreen.background(255,255,255);
TFTscreen.stroke(0,0,0);
// Horizontal lines
TFTscreen.line(0,61,160,61);
TFTscreen.line(0,62,160,62);
TFTscreen.line(0,63,160,63);
TFTscreen.line(0,93,160,93);
TFTscreen.line(0,31,160,31);
//vertical lines
TFTscreen.line(40,0,40,124);
TFTscreen.line(120,0,120,124);
TFTscreen.line(80,0,80,124);
}