4.3 tft drawing line "screen overflow ?"

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
iliaka
 
Posts: 10
Joined: Fri Jul 04, 2014 9:56 am

4.3 tft drawing line "screen overflow ?"

Post by iliaka »

Hi,
after/during facing SPI problems with SD card & TFT driver I hoped I can get easily through a mini project which shall display lines.
My hardware:
Arduino MEGA
TFT driver board RA8875
4.3 TFT
The wiring/hardware works.

I want to display 11 values which are connected by lines. The values are stored in an array and to display them I have a for-loop.
The distances between the values are the problem. Using distances=20 the graph will be shown perfectly. To use the whole width of screen I want to expand the distance between the values.
Using distance=30 the last 3 values start at the beginning of the screen. Even using distance=24, I have the "overflow" problem.
Calculate the maximum pixels I need when using distance=30 should be 380pixel (11x30+50). Way ahead from 480pixel of screen.
For better understanding I will attach 2 images and post the code.
Distance=20
Distance20.jpg
Distance20.jpg (862.54 KiB) Viewed 248 times
Image

Distance=30
Distance30.jpg
Distance30.jpg (892.61 KiB) Viewed 248 times
Image

Code: Select all

/******************************************************************
 This is an example for the Adafruit RA8875 Driver board for TFT displays
 ---------------> http://www.adafruit.com/products/1590
 The RA8875 is a TFT driver for up to 800x480 dotclock'd displays
 It is tested to work with displays in the Adafruit shop. Other displays
 may need timing adjustments and are not guanteed to work.
 
 Adafruit invests time and resources providing this open
 source code, please support Adafruit and open-source hardware
 by purchasing products from Adafruit!
 
 Written by Limor Fried/Ladyada for Adafruit Industries.
 BSD license, check license.txt for more information.
 All text above must be included in any redistribution.
 ******************************************************************/


#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"



// Library only supports hardware SPI at this time
// Connect SCLK to UNO Digital #13 (Hardware SPI clock)
// Connect MISO to UNO Digital #12 (Hardware SPI MISO)
// Connect MOSI to UNO Digital #11 (Hardware SPI MOSI)
#define RA8875_INT 3
#define RA8875_CS 10
#define RA8875_RESET 9

Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
uint16_t tx, ty;

void setup() 
{

  Serial.begin(9600);
  Serial.println("RA8875 start");
  
  /* Initialise the display using 'RA8875_480x272' or 'RA8875_800x480' */
  if (!tft.begin(RA8875_480x272)) {
    Serial.println("RA8875 Not Found!");
  //  while (1);
  }

  tft.displayOn(true);
  tft.GPIOX(true);      // Enable TFT - display enable tied to GPIOX
  tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
  tft.PWM1out(255);
  tft.fillScreen(RA8875_WHITE);

  /* Switch to text mode */  
  tft.textMode();
  
  /* Render some text! */
  char string100[5] = "100";
  tft.textTransparent(RA8875_RED);
  tft.textSetCursor(2, 40);
  tft.textEnlarge(1);
  tft.textWrite(string100);

  char string80[5] = "80";
  tft.textTransparent(RA8875_GREEN);
  tft.textSetCursor(2, 110);
  tft.textEnlarge(1);
  tft.textWrite(string80);

  char string50[5] = "50";
  tft.textTransparent(RA8875_BLUE);
  tft.textSetCursor(2, 170);
  tft.textEnlarge(1);
  tft.textWrite(string50);

  /* Switch to graphic mode */  
  tft.graphicsMode();
    
  tft.fillRect(20, 70, 460, 2, RA8875_RED);
  tft.fillRect(20, 110, 460, 2, RA8875_GREEN);
  tft.fillRect(20, 170, 460, 2, RA8875_BLUE);
  
  //Example array
  byte array_Graph []= {70,110,70,110,70,170,110,170,110,170,110};  //y-position of graph
  
  //drawing lines between
  byte col=50; //start with x-position= 50
  byte distance=20; //distance between x positions
  
    for (byte k=0; k < 10; k++) {
      tft.drawLine(col, array_Graph[k], (col+distance), array_Graph[k+1], RA8875_BLACK);
      tft.drawLine(col+1, array_Graph[k], (col+distance+1), array_Graph[k+1], RA8875_BLACK);
      col=col+distance; //next x-position 30pixel distance to previous position 
    }
}

void loop() 
{
}
Thank's a lot for your help.

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: 4.3 tft drawing line "screen overflow ?"

Post by Franklin97355 »

Code: Select all

 //drawing lines between
  byte col=50; //start with x-position= 50
try int col=50
Byte is 8 bits (0 to 255)

iliaka
 
Posts: 10
Joined: Fri Jul 04, 2014 9:56 am

Re: 4.3 tft drawing line "screen overflow ?"

Post by iliaka »

Hello franklin,

Thank you to showing me the most simplest error I could have done. I thouht about this but have overseen this. :(

Again, thanks.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”