
/*
  Arduino LCD-2000-9225 TFT text example For Mega2560
  
  This example demonstrates how to draw text on the 
  TFT with an Arduino. The Arduino reads the value 
  of an analog sensor attached to pin A0, and writes 
  the value to the LCD screen, updating every
  quarter second.
  
  This example code is in the public domain

  Created 30 April 2014 by INHAOS
 
  http://www.inhaos.com
 
 */

#include <LCD_2000_9225.h>
 
 // pin definition for the Uno
#define cs   40
#define wr   39
#define rs   38 
#define rst  41
#define le   42

#define D0	 37
#define D1	 36
#define D2	 35
#define D3	 34
#define D4	 33
#define D5	 32
#define D6	 31
#define D7	 30

LCD_2000_9225 TFTscreen(cs,wr,rs,rst,le);

// position of the line on screen
int xPos = 0;

void setup(){
  // initialize the serial port
  TFTscreen.setdatapin(D0,D1,D2,D3,D4,D5,D6,D7);
  TFTscreen.begin();

  // initialize the display
  TFTscreen.begin();

  // clear the screen with a pretty color
  TFTscreen.background(250,16,200); 
}

void loop(){
  // read the sensor and map it to the screen height
  int sensor = analogRead(A0);
  int drawHeight = map(sensor,0,1023,0,TFTscreen.height());
  
  // print out the height to the serial monitor
  Serial.println(drawHeight);
  
  // draw a line in a nice color
  TFTscreen.stroke(250,180,10);
  TFTscreen.line(xPos, TFTscreen.height()-drawHeight, xPos, TFTscreen.height());

  // if the graph has reached the screen edge
  // erase the screen and start again
  if (xPos >= 160) {
    xPos = 0;
    TFTscreen.background(250,16,200); 
  } 
  else {
    // increment the horizontal position:
    xPos++;
  }

  delay(16);
}

