3.2" TFT, sine wave and pot. How to erase old readings??

Hi all & Happy noo year.
I am trying to write a simple program that displays a sine wave on a 3.2" TFT touchscreen using the ITD graph16 library. I am using the basic demo code that I have striiped down so just a sine wave is shown which can be changed with a potentiometer connected to A8. I can get the sine wave to change but…I would like to know how to black out the old wave so I don’t get a screen full of sine waves…
The basic drawing code is here:

 for (int i=1; i<318; i++)
  {
      
     y=119+(sin(((i*1.13)*3.14)/pot/1.8)*(95)); // y co-ords
     myGLCD.setColor(0,255,255); // set color to cyan
    myGLCD.drawPixel(i,y); // draw the wave
    
    
    
   myGLCD.setColor(0,0,0);set to black
   
    myGLCD.drawPixel(i,y-1); // draw over old...doesn't work..
   
   
  }

So could someone please help me to work out how to then blank out the old wave when a new one is drawn?

CHeers,
Steve.

Several ways:- 1) Draw over the old wave in black. To do this you have to store the old wave and draw over it in black before you start drawing the new wave. This is not what that code you posted does. 2) Draw a black rectangle the size of the peak to peak waveform before drawing the new wave. 3) Clear the screen before drawing the new wave.

Alright Mike?
OK, thanks for your hints. I have just tried them all.
clearing the screen or drawing the rectangle worked but very slowly so I attempted suggestion 1.
y2 takes the value of “pot” and if it is different after a rendition of the wave it draws the old one in black!
like this:

for (int i=1; i<318; i++ )
  {
      y2=pot;   // pot value stored
       
     y=119+(sin(((i*1.13)*3.14)/pot/1.8)*(95)); //y co-ord
     myGLCD.setColor(0,255,255); // cyan pen
    myGLCD.drawPixel(i,y); // draw the wave
    
  }
 if (y2 >=pot) // self explanatory
 {
   for (int i=1; i<318; i++ ) // restart the loop
  {
    y=119+(sin(((i*1.13)*3.14)/pot/1.8)*(95)); // y co-ords
     myGLCD.setColor(0,0,0); // set pen to black
      myGLCD.drawPixel(i,y); //draw new wave
  }  
     
 }

and guess what!
It does work BUT its a bit flicky. The background frame holds but the wave flashes about once every 100ms. The wave is perfectly visible but does the code look right to you>
Do you think theres a way I could stop the flicker?

Thanks,
STeve.

Try and just erase the old line segment just before you update it and draw the new line segment. Rather than doing the whole wave at once. This will stop it from flickering.

hmm. I've tried putting the if statement inside the 1st for loop and adding the i++ at the end of the for loop sequence but the screen just shows a few dots where the sine wave should be that change with pot turns...this has me stumped! :s

I've tried putting the if statement inside the 1st for loop and adding the i++ at the end of the for loop sequence

That is not what I said. You have to store the values of the wave in an array in order for you to get them out and erase them during the next cycle. Then replace the old vlaue with the new one for next time.

Aaahhh!
Looking at the “moving sinewave” example in the demo sketch I noticed it uses a buffer.
A little changing of the code and implementation of my mapped pot (map, 0,1023,0,360)
and I got it workin’!

code:

// Draw  sinewave
  x=1;
  for (int i=1; i<(318); i++) 
  {
    
    x++;
    
   
      if ((x==159)||(buf[x-1]==119))
        myGLCD.setColor(0,0,255);
      
        myGLCD.setColor(0,0,0);
      myGLCD.drawPixel(x,buf[x-1]);
    
    myGLCD.setColor(0,255,255);
    y=119+(sin(((i*1.1)*3.14)/pot)*(90));
    y2=pot;
    myGLCD.drawPixel(x,y);
    buf[x-1]=y;
  }

So a flicker free pot adjusted sinewave!
One thing though…
It wobbles a little bit. In other words, the wave seems to wobble a few pixels from left to right…?
Any ideas?

the wave seems to wobble a few pixels from left to right

That will be because of the exact instance you start to acquire the samples to draw it is not the same each time. What are you using as a trigger?

Well, just a simple

 pot=analogRead(A8);
  map (pot,0,1023,0,360);

this is placed at the beginning of the loop() function before the for loop and the drawing of the wave...

which is then used to change the 2 pi f of the sine wave.

Another optimization you might take a look at si to check if the new line equals the old line. If so you do not need to draw any line at all => definitely no flicker