Fork of SPI18TFT: Ported to Seeeduino-Arch-Pro and tested with SainSmart 1.8 ST7735R TFT

Dependencies:   ST7735_TFT mbed

Fork of SPI18TFT by Jonne Valola

This port of the SPI18TFT demo program was to see if I could get a: SainSmart 1.8 ST7735R TFT LCD module to work with a Seeeduino-Arch-Pro mbed platform.

The gotcha is that this LCD module does not have an MSIO pin, and the MSIO pin on the Arch-Pro must be left disconnected.

main.cpp

Committer:
DevonHeron
Date:
2014-12-21
Revision:
1:71477b6fe9a4
Parent:
0:309c546f048d

File content as of revision 1:71477b6fe9a4:

 /*
 ***********************************************
 This works great on the Seeeduino-Arch-Pro using 
 the SainSmart 1.8" ST7735R TFT
 provided the wiring for the SPI bus is correct... 
 the MSIO pin can not be used for RS... 
 it must be disconnected
 ***********************************************
 */
 #include "stdio.h"
 #include "stdlib.h"
 #include "math.h"
 #include "mbed.h"
 #include "ST7735_TFT.h"
 #include "string"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 #include "Arial28x28.h"

 #define NUMBER_OF_STARS 300
 #define SCREEN_WIDTH 128
 #define SCREEN_HEIGHT 160
 
 /*star struct*/
typedef struct 
{
  float xpos, ypos;
  short zpos, speed;
  unsigned int color;
} STAR;

static STAR stars[NUMBER_OF_STARS];


void init_star(STAR* star, int i)
{
  /* randomly init stars, generate them around the center of the screen */
  
  star->xpos =  -10.0 + (20.0 * (rand()/(RAND_MAX+1.0)));
  star->ypos =  -10.0 + (20.0 * (rand()/(RAND_MAX+1.0)));
  
  star->xpos *= 3072.0; /*change viewpoint */
  star->ypos *= 3072.0;

  star->zpos =  i;
  star->speed =  2 + (int)(2.0 * (rand()/(RAND_MAX+1.0)));

  star->color = i*Cyan >> 2; /*the closer to the viewer the brighter*/
}


void init()
{
  int i;

  for (i = 0; i < NUMBER_OF_STARS; i++)
    {
      init_star(stars + i, i + 1);
    }
}
 
  
 // the TFT is connected to SPI pin 5-7, CS is p8, RS is p11, reset is p15 
 // ST7735_TFT TFT(p5, p6, p7, p8, p11, p15,"TFT"); // mosi, miso, sclk, cs, rs, reset
 ST7735_TFT TFT(P0_9,P0_8,P0_7,P0_6,P0_0,P2_13,"TFT"); // 
 
// Pins on the display    PIN on ARCH_Pro 
//  VCC    -- 3.3V
//  GND    -- GND
//  SCL    -- P0_7 
//  SDA    -- P0_9
//  RS /DC -- P0_0
//  RES    -- P2_13
//  CS     -- P0_6
//         -- P0_8  -- connection not used on display (sould be MISO)
 
 Serial pc(USBTX, USBRX); // tx, rx
 Timer t;

extern unsigned char p1[];  // the mbed logo
 
 int main() {
    printf("Getting Started Now\n\r");
    
    unsigned int centerx, centery;
    int i, j, tempx, tempy;  
    init();
    TFT.set_orientation(1);
    centerx = TFT.width() >> 1;
    centery = TFT.height() >> 1; 
    
     
    TFT.claim(stdout);      // send stdout to the TFT display 
    TFT.claim(stderr);      // send stderr to the TFT display

    TFT.background(Black);    // set background to black
    TFT.foreground(White);    // set chars to white
    
    TFT.cls();
    TFT.set_font((unsigned char*) Arial12x12);  // select the font
    
    TFT.printf("Getting Started\nLine two\nLine three\r\nEnd");
    pc.printf("Getting Started\nLine two\nLine three\r\nEnd");
    t.start();
    wait_ms(5000);
    ////// demo start
    
    printf("\n\n\n\n\nStart Time %f s\n", t.read());
    TFT.set_font((unsigned char*) Arial24x23);  // select the font
    for ( j = 0 ; j < 10000; j++ ) 
    {
     
      /* move and draw stars */
       
      for (i = 0; i < NUMBER_OF_STARS; i++)
    {
      tempx = (stars[i].xpos / stars[i].zpos) + centerx;
      tempy = (stars[i].ypos / stars[i].zpos) + centery;
      TFT.pixel(tempx,tempy,Black);
      
        
      stars[i].zpos -= stars[i].speed;
      
      if (stars[i].zpos <= 0)
        {
          init_star(stars + i, i + 1);
        }

      //compute 3D position
      tempx = (stars[i].xpos / stars[i].zpos) + centerx;
      tempy = (stars[i].ypos / stars[i].zpos) + centery;

      if (tempx < 0 || tempx > TFT.width() - 1 || tempy < 0 || tempy > TFT.height() - 1) //check if a star leaves the screen
        {
          init_star(stars + i, i + 1);
          continue;
        }
      
      TFT.pixel(tempx,tempy,stars[i].color);
        
    }
     TFT.Bitmap(centerx-60,centery-19,120,38,p1);
    }
    
    ///// demo stop

    t.stop();
    TFT.locate(0,10);
    TFT.set_font((unsigned char*) Arial12x12);  // select the font
    printf("Time %f s\n", t.read());
  }