2.4 inch tft touch shield drawing

Hi everyone, i am facing a problem when i try to draw on the tft screen… i will post the code

// UTFT_Demo_320x240 (C)2012 uCtronics
// web: http://www.uctronics.com
// UTFT_Demo_320x240 is derived from
// UTFT_Demo_320x240 (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
// to fit for our 3.2 inch TFT LCD shield for Arduino/Maple/Chipkit
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for modules with a screen resolution
// of 320x240 pixels.
//
// This program requires the UTFT library (8bit mode)
// and the code is compatible with both UNO and Mega board.
// No code modification required.
//

// if I want to use a GLUE class that implements the UTFT API
// with the Adafruit classes, I MUST include those headers
// because the Arduino Java does not look at nested includes !

#include <Adafruit_GFX.h>
//#include <Adafruit_TFTLCD.h> // this header is not needed
#include <UTFTGLUE.h> // class methods are in here
//UTFTGLUE myGLCD; // use for default shield
//UTFTGLUE myGLCD(0x9320,A2,A1,A3,A4,A0);
//UTFTGLUE myGLCD(0x9325,A2,A1,A3,A4,A0);
//UTFTGLUE myGLCD(0x7783,A2,A1,A3,A4,A0);
//UTFTGLUE myGLCD(0x1289,A1,A2,A0,0,A3); // this might choose the pins
UTFTGLUE myGLCD(0x0154,A2,A1,A3,A4,A0);

/*
#include <UTFT.h>
//#include <SD.h>
//UTFT myGLCD(ILI9325C,A2,A1,A3,A4); // Remember to change the model parameter to suit your display module!
//UTFT myGLCD(ILI9325D_8,A2,A1,A3,A4); // Remember to change the model parameter to suit your display module!
UTFT myGLCD(SSD1289_8,A1,A2,A0,A3); // Remember to change the model parameter to suit your display module!
*/

// Uncomment the next line for Arduino 2009/Uno
// UTFT(byte model, int RS, int WR,int CS,int RD)
//UTFT myGLCD(ILI9325C,A2,A1,A3,A0); // Remember to change the model parameter to suit your display module!
//Adafruit_UTFT myGLCD;

// Declare which fonts we will be using
extern uint8_t SmallFont;
int analog_in = A8;
unsigned long previousMillis = 0;
const long interval = 5;

void setup()
{
pinMode(A8, INPUT);
Serial.begin(9600);

// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
}

void loop()
{
int x;
// Clear the screen and draw the frame
myGLCD.clrScr();

myGLCD.setColor(0, 0, 255);
myGLCD.drawRect(0, 14, 319, 225);

unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
Serial.println(analogRead(A8)-70);

// Draw a moving sinewave
x = 1 ;
for (int i=1; i<(300*20); i++)
{
if (x < 319){

x ++ ;
myGLCD.setColor(0,255,255);
int y=(analogRead(A8)-70);
myGLCD.drawPixel(x,y);
delay(5);
}
else
{
x = 1;
myGLCD.clrScr();
}
}
}
}

from the above code, i am able to read the analog_input at A8 in to my y axis on the screen, and it does clear the screen after x reach to the maximum (very right to the screen) and draw again. however, i am just wondering its only showing number of pixels, so its not lines, how do i connect every pixel into lines?

First off, please edit your post to put the sketch inside code tags.

If you are porting a legacy UTFT sketch, it is very convenient to use the GLUE class.

For any new project it is far easier to use the native methods. I am not at a PC. I will post the equivalent sketch using the more intuitive Adafruit methods that are used by the MCUFRIEND_kbv class. (after I have taken my dog out)

If you have a contiguous curve like a Sine wave, dots are appropriate. Otherwise you simply draw a line between the previous and current point. In practice, it often looks better if you take the average of say 10 readings and draw lines between these points.

YMMV.

David.

how do i not contiguous the waves?..i just want to draw a simple line on the screen, the x axis just incresing 1 by 1, and y axis is the value from the analogue input pin 8.

Here is the same sketch:

#include <Adafruit_GFX.h>      //class includes
#include <MCUFRIEND_kbv.h>     //

MCUFRIEND_kbv tft;             //constructor

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define ANALOG_PIN A8          // I used a macro

int analog_in = ANALOG_PIN;    //a variable is just as good
unsigned long previousMillis = 0;
const long interval = 5;       // 5ms seems very short 

void setup()
{
    pinMode(ANALOG_PIN, INPUT); // is input anyway
    Serial.begin(9600);

    // Setup the LCD
    uint16_t ID = tft.readID();
    tft.begin(ID);         //you must always use the correct ID
    tft.setRotation(1);    //LANDSCAPE
    tft.fillScreen(BLACK); //start with blank screen
    tft.drawRect(0, 14, 320, 211, BLUE); //draw the frame
}

void loop()
{
    int x;
    unsigned long currentMillis = millis();

    if (currentMillis - previousMillis >= interval)
    {
        previousMillis = currentMillis;
        Serial.println(analogRead(ANALOG_PIN) - 70); //raw value from ADC

        for (int i = 1; i < (300 * 20); i++)
        {
            if (x < 318) {
                x++;
                int    adcval = analogRead(ANALOG_PIN); //adc is 0-1023
                int y = map(adcval, 0, 1023, 70, 208);  //map to 70-208
                tft.drawPixel(x, y, CYAN);
                delay(5);
            }
            else {
                x = 1;                                  //start again
                tft.fillRect(1, 15, 318, 209, BLACK);   //clear the frame
            }
        }
    }
}

I am not sure what you are trying to do. Every 5 milliseconds your sketch just takes 300 ADC readings in one burst.

I can see the point in logging slow values every 5 seconds. But you would normally take the average of 3 (or so) readings. Fast changing values still need to be human readable.

If you explain what you want to do in English, it is easier to program. What is your Sensor?

Regarding points, lines, disks, circles, triangles, … you choose what looks most attractive on your display.

In practice, colours look better than different shapes of “plot-point”

David.