Mapping temperature to a graph on a TFT LCD screen

@6v6gt
This is the code for drawing a graph, only I have absolutely NO idea how to map the temperature readings from a DS18B20 onto this graph. I only want to draw the temperature reading every 30 minutes.

void drawDetailScreenTemp() {
  tft.fillScreen(BLACK);

  tft.drawLine(0, 27, 480, 27, LIGHTGREY);
  tft.drawLine(0, 28, 480, 28, LIGHTGREY);
  tft.drawLine(200, 0, 200, 28, LIGHTGREY);
  tft.drawLine(201, 0, 201, 28, LIGHTGREY);

  myRTC.updateTime();
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.setCursor(5, 3);
  if (myRTC.dayofmonth < 10)
  {
    tft.print("0");
    tft.print(myRTC.dayofmonth);
  }
  else
  {
    tft.print(myRTC.dayofmonth);
  }
  tft.print("/");
  if (myRTC.month < 10) {
    tft.print("0");
    tft.print(myRTC.month);
  }
  else {
    tft.print(myRTC.month);
  }
  tft.print("/");
  tft.print(myRTC.year);
  tft.setCursor(206, 3);
  if (myRTC.hours < 10) {
    tft.print("0");
    tft.print(myRTC.hours);
  }
  else {
    tft.print(myRTC.hours);
  }
  tft.print(":");
  if (myRTC.minutes < 10) {
    tft.print("0");
    tft.print(myRTC.minutes);
  }
  else {
    tft.print(myRTC.minutes);
  }
  int sensor = analogRead(A1);
  float voltage = (sensor * 5.0) / 1023;
  battery();
  tft.drawLine(27, 33, 339, 33, LIGHTGREY);
  tft.drawLine(27, 59, 339, 59, LIGHTGREY);
  tft.drawLine(27, 85, 339, 85, LIGHTGREY);
  tft.drawLine(27, 111, 339, 111, LIGHTGREY);
  tft.drawLine(27, 137, 339, 137, LIGHTGREY);
  tft.drawLine(27, 163, 339, 163, LIGHTGREY);
  tft.drawLine(27, 189, 339, 189, LIGHTGREY);
  tft.drawLine(27, 215, 339, 215, LIGHTGREY);
  tft.drawLine(27, 241, 339, 241, LIGHTGREY);
  tft.drawLine(27, 267, 339, 267, LIGHTGREY);
  tft.drawLine(27, 293, 339, 293, LIGHTGREY);

  tft.drawLine(339, 33, 339, 293, LIGHTGREY);
  tft.drawLine(313, 33, 313, 293, LIGHTGREY);
  tft.drawLine(287, 33, 287, 293, LIGHTGREY);
  tft.drawLine(261, 33, 261, 293, LIGHTGREY);
  tft.drawLine(236, 33, 236, 293, LIGHTGREY);
  tft.drawLine(209, 33, 209, 293, LIGHTGREY);
  tft.drawLine(183, 33, 183, 293, LIGHTGREY);
  tft.drawLine(157, 33, 157, 293, LIGHTGREY);
  tft.drawLine(131, 33, 131, 293, LIGHTGREY);
  tft.drawLine(105, 33, 105, 293, LIGHTGREY);
  tft.drawLine(79, 33, 79, 293, LIGHTGREY);
  tft.drawLine(53, 33, 53, 293, LIGHTGREY);
  tft.drawLine(27, 33, 27, 293, LIGHTGREY);

  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(6, 33);
  tft.print("45");
  tft.print((char)247);
  tft.setCursor(6, 59);
  tft.print("40");
  tft.print((char)247);
  tft.setCursor(6, 85);
  tft.print("35");
  tft.print((char)247);
  tft.setCursor(6, 111);
  tft.print("30");
  tft.print((char)247);
  tft.setCursor(6, 137);
  tft.print("25");
  tft.print((char)247);
  tft.setCursor(6, 163);
  tft.print("20");
  tft.print((char)247);
  tft.setCursor(6, 189);
  tft.print("15");
  tft.print((char)247);
  tft.setCursor(6, 215);
  tft.print("10");
  tft.print((char)247);
  tft.setCursor(6, 241);
  tft.print(" 5");
  tft.print((char)247);
  tft.setCursor(6, 267);
  tft.print(" 0");
  tft.print((char)247);
  tft.setCursor(6, 285);
  tft.print("-5");
  tft.print((char)247);

  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(26, 300);
  tft.print("6");
  tft.setCursor(44, 300);
  tft.print("5.5");
  tft.setCursor(77, 300);
  tft.print("5");
  tft.setCursor(96, 300);
  tft.print("4.5");
  tft.setCursor(128, 300);
  tft.print("4");
  tft.setCursor(148, 300);
  tft.print("3.5");
  tft.setCursor(181, 300);
  tft.print("3");
  tft.setCursor(200, 300);
  tft.print("2.5");
  tft.setCursor(234, 300);
  tft.print("2");
  tft.setCursor(253, 300);
  tft.print("1.5");
  tft.setCursor(285, 300);
  tft.print("1");
  tft.setCursor(305, 300);
  tft.print("0.5");
  tft.setCursor(337, 300);
  tft.print("0");
}

Does anyone know how to do this? I haven't been able to find any working code for doing this with this sensor.
Thanks in advance!

The sensor is immaterial, data is data. The simplest way to do this is to convert the data to a sensible y coordinate and place a pixel there at the x interval you have already determined. The code you post is incomplete and meaningless, but the above principle would apply to any display and there is bound to be an example of what you essentially need included in the library for your particular display. This is likely to be an example of a sine wave.

Two Speed graph sm

@Nick_Pyner
The complete code is as follows:

#include "Full.c"
#include "Draining.c"
#include "Drained.c"
#include "Empty.c"
#include "Charging.c"

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 1000

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

#define USE_TOUCH    0x2046

#include <virtuabotixRTC.h> //Libraries needed

virtuabotixRTC myRTC(6, 7, 8);

#include "Adafruit_GFX.h"    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
#include <SPI.h>
#include <SD.h>
MCUFRIEND_kbv tft;       //
#define TFT_BEGIN()    tft.begin(0x9488)

#include <XPT2046_Touchscreen.h>           // Hardware SPI library
char *name = "Shield XPT2046 Calibration";  //edit name of shield
const int TS_LANDSCAPE = 1; //XPT2046_TouchScreen.h
const int TS_LEFT = 261, TS_RT = 3770, TS_TOP = 3869, TS_BOT = 296;
#define XPT_CS  53      // MEGA2560 SHIELD 
#define XPT_IRQ 255     // XPT2046 library does not like IRQ
XPT2046_Touchscreen ts(XPT_CS, XPT_IRQ);

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
  bool pressed = ts.touched();
  if (pressed) {
    TS_Point p = ts.getPoint();
    if (TS_LANDSCAPE) mapxy(p.y, p.x);
    else mapxy(p.x, p.y);
  }
  return pressed;
}

void Touch_init(void)
{
  ts.begin();
}

void mapxy(int x, int y)                //maps ADC to pixel_x, pixel_y
{
  int aspect = tft.getRotation();     //LANDSCAPE
  int tft_width = tft.width();
  int tft_height = tft.height();
  switch (aspect & 3) {
    case 0:      //PORTRAIT
      pixel_x = map(x, TS_LEFT, TS_RT, 0, tft_width);
      pixel_y = map(y, TS_TOP, TS_BOT, 0, tft_height);
      break;
    case 1:      //LANDSCAPE
      pixel_x = map(y, TS_TOP, TS_BOT, 0, tft_width);
      pixel_y = map(x, TS_RT, TS_LEFT, 0, tft_height);
      break;
    case 2:      //PORTRAIT REV
      pixel_x = map(x, TS_RT, TS_LEFT, 0, tft_width);
      pixel_y = map(y, TS_BOT, TS_TOP, 0, tft_height);
      break;
    case 3:      //LANDSCAPE REV
      pixel_x = map(y, TS_BOT, TS_TOP, 0, tft_width);
      pixel_y = map(x, TS_LEFT, TS_RT, 0, tft_height);
      break;
  }
}

Adafruit_GFX_Button temp_btn, humidity_btn, home_btn, more_btn;

#define BLACK 0x0000       /*   0,   0,   0 */
#define NAVY 0x000F        /*   0,   0, 128 */
#define DARKGREEN 0x03E0   /*   0, 128,   0 */
#define DARKCYAN 0x03EF    /*   0, 128, 128 */
#define MAROON 0x7800      /* 128,   0,   0 */
#define PURPLE 0x780F      /* 128,   0, 128 */
#define OLIVE 0x7BE0       /* 128, 128,   0 */
#define LIGHTGREY 0xC618   /* 192, 192, 192 */
#define DARKGREY 0x7BEF    /* 128, 128, 128 */
#define BLUE 0x001F        /*   0,   0, 255 */
#define GREEN 0x07E0       /*   0, 255,   0 */
#define CYAN 0x07FF        /*   0, 255, 255 */
#define RED 0xF800         /* 255,   0,   0 */
#define MAGENTA 0xF81F     /* 255,   0, 255 */
#define YELLOW 0xFFE0      /* 255, 255,   0 */
#define WHITE 0xFFFF       /* 255, 255, 255 */
#define ORANGE 0xFD20      /* 255, 165,   0 */
#define GREENYELLOW 0xAFE5 /* 173, 255,  47 */
#define PINK 0xF81F

uint8_t displayScreenNo;

void setup() {
  Serial.begin(9600);
  sensors.begin();
  TFT_BEGIN();
  Touch_init();
  Serial.println("Calibrate for your Touch Panel");
  tft.setRotation(1);            //PORTRAIT
  tft.fillScreen(BLACK);
  home_btn.initButton(&tft,  440, 280, 80, 80, LIGHTGREY, CYAN, BLACK, "HOME", 2);
  home_btn.drawButton(false);
  more_btn.initButton(&tft,  440, 40, 80, 80, LIGHTGREY, CYAN, BLACK, "MORE", 2);
  more_btn.drawButton(false);
  temp_btn.initButton(&tft,  440, 120, 80, 80, LIGHTGREY, CYAN, BLACK, "TEMP", 2);
  humidity_btn.initButton(&tft, 440, 200, 80, 80, LIGHTGREY, CYAN, BLACK, "%", 2);
  temp_btn.drawButton(false);
  humidity_btn.drawButton(false);
  tft.setTextSize(3);
}

void loop() {
  bool down = Touch_getXY();
  home_btn.press(down && home_btn.contains(pixel_x, pixel_y));
  more_btn.press(down && more_btn.contains(pixel_x, pixel_y));
  temp_btn.press(down && temp_btn.contains(pixel_x, pixel_y));
  humidity_btn.press(down && humidity_btn.contains(pixel_x, pixel_y));
  if (home_btn.justReleased()) {
    home_btn.drawButton(true);
    more_btn.drawButton();
    temp_btn.drawButton();
    humidity_btn.drawButton();
  }
  if (more_btn.justReleased()) {
    more_btn.drawButton();
    home_btn.drawButton();
    temp_btn.drawButton();
    humidity_btn.drawButton();
  }
  if (temp_btn.justReleased()) {
    home_btn.drawButton();
    temp_btn.drawButton();
    more_btn.drawButton();
    humidity_btn.drawButton();
  }
  if (humidity_btn.justReleased()) {
    home_btn.drawButton();
    temp_btn.drawButton();
    humidity_btn.drawButton();
    more_btn.drawButton();
  }
  if (home_btn.justPressed())
  {
    displayScreenNo = 1;
    home_btn.drawButton(true);
    temp_btn.drawButton(false);
    humidity_btn.drawButton(false);
    more_btn.drawButton(false);
  }
  if (more_btn.justPressed())
  {
    displayScreenNo = 2;
    more_btn.drawButton(true);
    temp_btn.drawButton(false);
    humidity_btn.drawButton(false);
    home_btn.drawButton(false);
  }
  if (temp_btn.justPressed())
  {
    displayScreenNo = 3;
    temp_btn.drawButton(true);
    home_btn.drawButton(false);
    humidity_btn.drawButton(false);
    more_btn.drawButton(false);
  }
  if (humidity_btn.justPressed())
  {
    displayScreenNo = 4;
    humidity_btn.drawButton(true);
    temp_btn.drawButton(false);
    home_btn.drawButton(false);
    more_btn.drawButton(false);
  }
  static uint32_t prevMillis = 0;
  if (millis() - prevMillis > 1000 ) {
    prevMillis = millis() ;
    if ( displayScreenNo == 1 ) drawHomeScreen();
    else if ( displayScreenNo == 2 ) drawMoreScreen();
    else if ( displayScreenNo == 3 ) drawDetailScreenTemp();
    else if ( displayScreenNo == 4 ) drawDetailScreenHumidity();
  }
}

void drawHomeScreen() {
  sensors.requestTemperatures();

  tft.fillScreen(BLACK);

  tft.drawLine(0, 27, 480, 27, LIGHTGREY);
  tft.drawLine(0, 28, 480, 28, LIGHTGREY);
  tft.drawLine(200, 0, 200, 28, LIGHTGREY);
  tft.drawLine(201, 0, 201, 28, LIGHTGREY);

  tft.drawLine(0, 288, 480, 288, LIGHTGREY);
  tft.drawLine(0, 289, 480, 289, LIGHTGREY);
  tft.drawLine(200, 288, 200, 320, LIGHTGREY);
  tft.drawLine(201, 289, 201, 320, LIGHTGREY);

  myRTC.updateTime();
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.setCursor(5, 3);
  if (myRTC.dayofmonth < 10)
  {
    tft.print("0");
    tft.print(myRTC.dayofmonth);
  }
  else
  {
    tft.print(myRTC.dayofmonth);
  }
  tft.print("/");
  if (myRTC.month < 10) {
    tft.print("0");
    tft.print(myRTC.month);
  }
  else {
    tft.print(myRTC.month);
  }
  tft.print("/");
  tft.print(myRTC.year);
  tft.setCursor(206, 3);
  if (myRTC.hours < 10) {
    tft.print("0");
    tft.print(myRTC.hours);
  }
  else {
    tft.print(myRTC.hours);
  }
  tft.print(":");
  if (myRTC.minutes < 10) {
    tft.print("0");
    tft.print(myRTC.minutes);
  }
  else {
    tft.print(myRTC.minutes);
  }
  int sensor = analogRead(A1);
  float voltage = (sensor * 5.0) / 1023;
  battery();

  tft.setCursor(5, 294);
  tft.fillRect(5, 294, 90, 21, BLACK);
  tft.print(sensors.getTempCByIndex(0));
  tft.print(" ");
  tft.print((char)247);
  tft.print("C");
  buttons();
}

void drawDetailScreenHumidity() {
  tft.fillScreen(BLACK);

  tft.drawLine(0, 27, 480, 27, LIGHTGREY);
  tft.drawLine(0, 28, 480, 28, LIGHTGREY);
  tft.drawLine(200, 0, 200, 28, LIGHTGREY);
  tft.drawLine(201, 0, 201, 28, LIGHTGREY);

  myRTC.updateTime();
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.setCursor(5, 3);
  if (myRTC.dayofmonth < 10)
  {
    tft.print("0");
    tft.print(myRTC.dayofmonth);
  }
  else
  {
    tft.print(myRTC.dayofmonth);
  }
  tft.print("/");
  if (myRTC.month < 10) {
    tft.print("0");
    tft.print(myRTC.month);
  }
  else {
    tft.print(myRTC.month);
  }
  tft.print("/");
  tft.print(myRTC.year);
  tft.setCursor(206, 3);
  if (myRTC.hours < 10) {
    tft.print("0");
    tft.print(myRTC.hours);
  }
  else {
    tft.print(myRTC.hours);
  }
  tft.print(":");
  if (myRTC.minutes < 10) {
    tft.print("0");
    tft.print(myRTC.minutes);
  }
  else {
    tft.print(myRTC.minutes);
  }
  int sensor = analogRead(A1);
  float voltage = (sensor * 5.0) / 1023;
  battery();
  tft.drawLine(27, 33, 339, 33, LIGHTGREY);
  tft.drawLine(27, 59, 339, 59, LIGHTGREY);
  tft.drawLine(27, 85, 339, 85, LIGHTGREY);
  tft.drawLine(27, 111, 339, 111, LIGHTGREY);
  tft.drawLine(27, 137, 339, 137, LIGHTGREY);
  tft.drawLine(27, 163, 339, 163, LIGHTGREY);
  tft.drawLine(27, 189, 339, 189, LIGHTGREY);
  tft.drawLine(27, 215, 339, 215, LIGHTGREY);
  tft.drawLine(27, 241, 339, 241, LIGHTGREY);
  tft.drawLine(27, 267, 339, 267, LIGHTGREY);
  tft.drawLine(27, 293, 339, 293, LIGHTGREY);

  tft.drawLine(339, 33, 339, 293, LIGHTGREY);
  tft.drawLine(313, 33, 313, 293, LIGHTGREY);
  tft.drawLine(287, 33, 287, 293, LIGHTGREY);
  tft.drawLine(261, 33, 261, 293, LIGHTGREY);
  tft.drawLine(236, 33, 236, 293, LIGHTGREY);
  tft.drawLine(209, 33, 209, 293, LIGHTGREY);
  tft.drawLine(183, 33, 183, 293, LIGHTGREY);
  tft.drawLine(157, 33, 157, 293, LIGHTGREY);
  tft.drawLine(131, 33, 131, 293, LIGHTGREY);
  tft.drawLine(105, 33, 105, 293, LIGHTGREY);
  tft.drawLine(79, 33, 79, 293, LIGHTGREY);
  tft.drawLine(53, 33, 53, 293, LIGHTGREY);
  tft.drawLine(27, 33, 27, 293, LIGHTGREY);

  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(2, 33);
  tft.print("100%");
  tft.setCursor(6, 59);
  tft.print("90%");
  tft.setCursor(6, 85);
  tft.print("80%");
  tft.setCursor(6, 111);
  tft.print("70%");
  tft.setCursor(6, 137);
  tft.print("60%");
  tft.setCursor(6, 163);
  tft.print("50%");
  tft.setCursor(6, 189);
  tft.print("40%");
  tft.setCursor(6, 215);
  tft.print("30%");
  tft.setCursor(6, 241);
  tft.print("20%");
  tft.setCursor(6, 267);
  tft.print("10%");
  tft.setCursor(6, 293);
  tft.print("0%");

  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(26, 300);
  tft.print("6");
  tft.setCursor(44, 300);
  tft.print("5.5");
  tft.setCursor(77, 300);
  tft.print("5");
  tft.setCursor(96, 300);
  tft.print("4.5");
  tft.setCursor(128, 300);
  tft.print("4");
  tft.setCursor(148, 300);
  tft.print("3.5");
  tft.setCursor(181, 300);
  tft.print("3");
  tft.setCursor(200, 300);
  tft.print("2.5");
  tft.setCursor(234, 300);
  tft.print("2");
  tft.setCursor(253, 300);
  tft.print("1.5");
  tft.setCursor(285, 300);
  tft.print("1");
  tft.setCursor(305, 300);
  tft.print("0.5");
  tft.setCursor(337, 300);
  tft.print("0");
  buttons();
}

void drawMoreScreen() {
  //tft.fillScreen(BLACK);
  buttons();
}

void drawDetailScreenTemp() {
  tft.fillScreen(BLACK);

  tft.drawLine(0, 27, 480, 27, LIGHTGREY);
  tft.drawLine(0, 28, 480, 28, LIGHTGREY);
  tft.drawLine(200, 0, 200, 28, LIGHTGREY);
  tft.drawLine(201, 0, 201, 28, LIGHTGREY);

  myRTC.updateTime();
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.setCursor(5, 3);
  if (myRTC.dayofmonth < 10)
  {
    tft.print("0");
    tft.print(myRTC.dayofmonth);
  }
  else
  {
    tft.print(myRTC.dayofmonth);
  }
  tft.print("/");
  if (myRTC.month < 10) {
    tft.print("0");
    tft.print(myRTC.month);
  }
  else {
    tft.print(myRTC.month);
  }
  tft.print("/");
  tft.print(myRTC.year);
  tft.setCursor(206, 3);
  if (myRTC.hours < 10) {
    tft.print("0");
    tft.print(myRTC.hours);
  }
  else {
    tft.print(myRTC.hours);
  }
  tft.print(":");
  if (myRTC.minutes < 10) {
    tft.print("0");
    tft.print(myRTC.minutes);
  }
  else {
    tft.print(myRTC.minutes);
  }
  int sensor = analogRead(A1);
  float voltage = (sensor * 5.0) / 1023;
  battery();
  tft.drawLine(27, 33, 339, 33, LIGHTGREY);
  tft.drawLine(27, 59, 339, 59, LIGHTGREY);
  tft.drawLine(27, 85, 339, 85, LIGHTGREY);
  tft.drawLine(27, 111, 339, 111, LIGHTGREY);
  tft.drawLine(27, 137, 339, 137, LIGHTGREY);
  tft.drawLine(27, 163, 339, 163, LIGHTGREY);
  tft.drawLine(27, 189, 339, 189, LIGHTGREY);
  tft.drawLine(27, 215, 339, 215, LIGHTGREY);
  tft.drawLine(27, 241, 339, 241, LIGHTGREY);
  tft.drawLine(27, 267, 339, 267, LIGHTGREY);
  tft.drawLine(27, 293, 339, 293, LIGHTGREY);

  tft.drawLine(339, 33, 339, 293, LIGHTGREY);
  tft.drawLine(313, 33, 313, 293, LIGHTGREY);
  tft.drawLine(287, 33, 287, 293, LIGHTGREY);
  tft.drawLine(261, 33, 261, 293, LIGHTGREY);
  tft.drawLine(236, 33, 236, 293, LIGHTGREY);
  tft.drawLine(209, 33, 209, 293, LIGHTGREY);
  tft.drawLine(183, 33, 183, 293, LIGHTGREY);
  tft.drawLine(157, 33, 157, 293, LIGHTGREY);
  tft.drawLine(131, 33, 131, 293, LIGHTGREY);
  tft.drawLine(105, 33, 105, 293, LIGHTGREY);
  tft.drawLine(79, 33, 79, 293, LIGHTGREY);
  tft.drawLine(53, 33, 53, 293, LIGHTGREY);
  tft.drawLine(27, 33, 27, 293, LIGHTGREY);

  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(6, 33);
  tft.print("45");
  tft.print((char)247);
  tft.setCursor(6, 59);
  tft.print("40");
  tft.print((char)247);
  tft.setCursor(6, 85);
  tft.print("35");
  tft.print((char)247);
  tft.setCursor(6, 111);
  tft.print("30");
  tft.print((char)247);
  tft.setCursor(6, 137);
  tft.print("25");
  tft.print((char)247);
  tft.setCursor(6, 163);
  tft.print("20");
  tft.print((char)247);
  tft.setCursor(6, 189);
  tft.print("15");
  tft.print((char)247);
  tft.setCursor(6, 215);
  tft.print("10");
  tft.print((char)247);
  tft.setCursor(6, 241);
  tft.print(" 5");
  tft.print((char)247);
  tft.setCursor(6, 267);
  tft.print(" 0");
  tft.print((char)247);
  tft.setCursor(6, 285);
  tft.print("-5");
  tft.print((char)247);

  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(26, 300);
  tft.print("6");
  tft.setCursor(44, 300);
  tft.print("5.5");
  tft.setCursor(77, 300);
  tft.print("5");
  tft.setCursor(96, 300);
  tft.print("4.5");
  tft.setCursor(128, 300);
  tft.print("4");
  tft.setCursor(148, 300);
  tft.print("3.5");
  tft.setCursor(181, 300);
  tft.print("3");
  tft.setCursor(200, 300);
  tft.print("2.5");
  tft.setCursor(234, 300);
  tft.print("2");
  tft.setCursor(253, 300);
  tft.print("1.5");
  tft.setCursor(285, 300);
  tft.print("1");
  tft.setCursor(305, 300);
  tft.print("0.5");
  tft.setCursor(337, 300);
  tft.print("0");

  buttons();
}

void battery () {
  int sensor = analogRead(A1);
  //Serial.println(sensor);
  float voltage = (sensor * 5.0) / 1023;
  //Serial.println(voltage);
  if (voltage > 3.00) {
    tft.drawRGBBitmap(355, 3, Charging, 36, 21);
  }
  if ((voltage <= 3.00) && (voltage > 2.35)) {
    tft.drawRGBBitmap(355, 3, Full, 36, 21);
  }
  if ((voltage <= 2.35) && (voltage > 1.70)) {
    tft.drawRGBBitmap(355, 3, Draining, 36, 21);
  }
  if ((voltage <= 1.70) && (voltage > 1.00)) {
    tft.drawRGBBitmap(355, 3, Drained, 36, 21);
  }
  if (voltage <= 1.00) {
    tft.drawRGBBitmap(355, 3, Empty, 36, 21);
  }
}

void buttons () {
  home_btn.drawButton(false);
  more_btn.drawButton(false);
  temp_btn.drawButton(false);
  humidity_btn.drawButton(false);
}

I realise that, but how do you turn it into that?? And no, there is no example of what I want in the library. Absolutely none whatsoever. I have checked every single example already.

You see all those setCursor() statements? They're plotting the grid. It looks like the legends are in %. So scale your data as %. Then the formula is:

y = ymin + (datum% * (ymax - ymin) / 100);

ymax-ymin is the number of pixels vertically in the plotting area. The datum is in percent, hence the 100 divisor. You iterate thru x. Look at the setCursor() statements.

@madmark2150
That's the info I've figured out.

ymin = 33;
ymax = 293;

y = ymin + (datum % * (ymax - ymin) / 100);

What is

datum%

and how do I tell my arduino what that is?

What do you mean by

That's true for part of it, the other part is degrees celcius.

Sorry, but I've never done this sort of thing before, so I need everything explained.

Here's the new code:

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 1000

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

#include "Adafruit_GFX.h"    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define BLACK 0x0000       /*   0,   0,   0 */
#define NAVY 0x000F        /*   0,   0, 128 */
#define DARKGREEN 0x03E0   /*   0, 128,   0 */
#define DARKCYAN 0x03EF    /*   0, 128, 128 */
#define MAROON 0x7800      /* 128,   0,   0 */
#define PURPLE 0x780F      /* 128,   0, 128 */
#define OLIVE 0x7BE0       /* 128, 128,   0 */
#define LIGHTGREY 0xC618   /* 192, 192, 192 */
#define DARKGREY 0x7BEF    /* 128, 128, 128 */
#define BLUE 0x001F        /*   0,   0, 255 */
#define GREEN 0x07E0       /*   0, 255,   0 */
#define CYAN 0x07FF        /*   0, 255, 255 */
#define RED 0xF800         /* 255,   0,   0 */
#define MAGENTA 0xF81F     /* 255,   0, 255 */
#define YELLOW 0xFFE0      /* 255, 255,   0 */
#define WHITE 0xFFFF       /* 255, 255, 255 */
#define ORANGE 0xFD20      /* 255, 165,   0 */
#define GREENYELLOW 0xAFE5 /* 173, 255,  47 */
#define PINK 0xF81F

/*
ymin = 33;
ymax = 293;

y = ymin + (datum % * (ymax - ymin) / 100);
*/

void setup() {
  Serial.begin(9600);
  sensors.begin();
  tft.begin(0x9488);
  tft.setRotation(1);            //PORTRAIT
  tft.fillScreen(BLACK);
  tft.setTextSize(3);
}

void loop() {
  graph();
}






/*You see all those setCursor() statements ? They're plotting the grid. It looks like the legends are in %. So scale your data as %. Then the formula is:

y = ymin + (datum% * (ymax - ymin) / 100);

ymax-ymin is the number of pixels vertically in the plotting area. The datum is in percent, hence the 100 divisor. You iterate thru x. Look at the setCursor() statements.

*/

void graph(){
tft.drawLine(27, 33, 339, 33, LIGHTGREY);
tft.drawLine(27, 59, 339, 59, LIGHTGREY);
tft.drawLine(27, 85, 339, 85, LIGHTGREY);
tft.drawLine(27, 111, 339, 111, LIGHTGREY);
tft.drawLine(27, 137, 339, 137, LIGHTGREY);
tft.drawLine(27, 163, 339, 163, LIGHTGREY);
tft.drawLine(27, 189, 339, 189, LIGHTGREY);
tft.drawLine(27, 215, 339, 215, LIGHTGREY);
tft.drawLine(27, 241, 339, 241, LIGHTGREY);
tft.drawLine(27, 267, 339, 267, LIGHTGREY);
tft.drawLine(27, 293, 339, 293, LIGHTGREY);

tft.drawLine(339, 33, 339, 293, LIGHTGREY);
tft.drawLine(313, 33, 313, 293, LIGHTGREY);
tft.drawLine(287, 33, 287, 293, LIGHTGREY);
tft.drawLine(261, 33, 261, 293, LIGHTGREY);
tft.drawLine(236, 33, 236, 293, LIGHTGREY);
tft.drawLine(209, 33, 209, 293, LIGHTGREY);
tft.drawLine(183, 33, 183, 293, LIGHTGREY);
tft.drawLine(157, 33, 157, 293, LIGHTGREY);
tft.drawLine(131, 33, 131, 293, LIGHTGREY);
tft.drawLine(105, 33, 105, 293, LIGHTGREY);
tft.drawLine(79, 33, 79, 293, LIGHTGREY);
tft.drawLine(53, 33, 53, 293, LIGHTGREY);
tft.drawLine(27, 33, 27, 293, LIGHTGREY);

tft.setTextSize(1);
tft.setTextColor(LIGHTGREY);
tft.setCursor(6, 33);
tft.print("45");
tft.print((char)247);
tft.setCursor(6, 59);
tft.print("40");
tft.print((char)247);
tft.setCursor(6, 85);
tft.print("35");
tft.print((char)247);
tft.setCursor(6, 111);
tft.print("30");
tft.print((char)247);
tft.setCursor(6, 137);
tft.print("25");
tft.print((char)247);
tft.setCursor(6, 163);
tft.print("20");
tft.print((char)247);
tft.setCursor(6, 189);
tft.print("15");
tft.print((char)247);
tft.setCursor(6, 215);
tft.print("10");
tft.print((char)247);
tft.setCursor(6, 241);
tft.print(" 5");
tft.print((char)247);
tft.setCursor(6, 267);
tft.print(" 0");
tft.print((char)247);
tft.setCursor(6, 285);
tft.print("-5");
tft.print((char)247);

tft.setTextSize(1);
tft.setTextColor(LIGHTGREY);
tft.setCursor(26, 300);
tft.print("6");
tft.setCursor(44, 300);
tft.print("5.5");
tft.setCursor(77, 300);
tft.print("5");
tft.setCursor(96, 300);
tft.print("4.5");
tft.setCursor(128, 300);
tft.print("4");
tft.setCursor(148, 300);
tft.print("3.5");
tft.setCursor(181, 300);
tft.print("3");
tft.setCursor(200, 300);
tft.print("2.5");
tft.setCursor(234, 300);
tft.print("2");
tft.setCursor(253, 300);
tft.print("1.5");
tft.setCursor(285, 300);
tft.print("1");
tft.setCursor(305, 300);
tft.print("0.5");
tft.setCursor(337, 300);
tft.print("0");
}

@madmark2150


Where do I define ymin, ymax, y?

@madmark2150
This code works:

#include "Adafruit_GFX.h"    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
#include "Universum_TFTColours.h" // Universum library for colours
#include <OneWire.h>
#include <DallasTemperature.h>

MCUFRIEND_kbv tft;

#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 1000

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

// Global variables
int valueBlock[500];
int timeBlock[500];
int locationBlock[500];
int valuePos;
int blockPos;
int temp;

// Editable Variables
bool proDebug = 0;

uint16_t graphColor = BLUE;
uint16_t pointColor = BLACK;
uint16_t lineColor = GREEN;

String graphName = "Temp Graph";

int graphRange = 50;
int markSize = 3;

// Calculate Values
const int numberOfMarks = 8;
const int originX = 45;
const int originY = 200;
const int sizeX = 270;
const int sizeY = 150;
const int deviation = 30;

int boxSize = (sizeX / numberOfMarks);
int mark[] = {(boxSize + deviation), ((boxSize * 2) + deviation), ((boxSize * 3) + deviation), ((boxSize * 4) + deviation), ((boxSize * 5) + deviation), ((boxSize * 6) + deviation), ((boxSize * 7) + deviation), ((boxSize * 8) + deviation)};

const int minorSizeY = (originY + 10);
const int minorSizeX = (originX - 10);

int numberSize = (sizeY / 6);
int number[] = {numberSize, (numberSize * 2), (numberSize * 3), (numberSize * 4), (numberSize * 5), (numberSize * 6)};

int numberValue = (graphRange / 6);
int val[] = {graphRange, (numberValue * 5), (numberValue * 4), (numberValue * 3), (numberValue * 2), numberValue};

void drawHome()
{
  tft.fillScreen(BLACK);
  delay(500);

  tft.setCursor(10, 10); // set the cursor
  tft.setTextColor(BLUE); // set the colour of the text
  tft.setTextSize(5); // set the size of the text
  tft.println("DS18B20");

  tft.setCursor(10, 80); // set the cursor
  tft.setTextColor(CYAN); // set the colour of the text
  tft.setTextSize(3); // set the size of the text
  tft.println("Graphing");

  tft.setCursor(30, 110); // set the cursor
  tft.setTextColor(CYAN); // set the colour of the text
  tft.setTextSize(2); // set the size of the text
  tft.println("History Graphs");

  tft.setCursor(10, 160); // set the cursor
  tft.setTextColor(WHITE); // set the colour of the text
  tft.setTextSize(2); // set the size of the text
  tft.println("Daniel Van Nattan");
  delay(4000);

  tft.fillScreen(WHITE);
  delay(500);
}

void drawGraph()
{
  // draw title
  tft.setCursor(10, 10); // set the cursor
  tft.setTextColor(BLUE); // set the colour of the text
  tft.setTextSize(4); // set the size of the text
  tft.println(graphName);

  // draw outline
  tft.drawLine(originX, originY, (originX + sizeX), originY, graphColor);
  tft.drawLine(originX, originY, originX, (originY - sizeY), graphColor);

  // draw lables
  for (int i = 0; i < numberOfMarks; i++)
  {
    tft.drawLine(mark[i], originY, mark[i], minorSizeY, graphColor);
  }

  // draw numbers
  for (int i = 0; i < 6; i++)
  {
    tft.drawLine(originX, (originY - number[i]), minorSizeX, (originY - number[i]), graphColor);
  }

  // draw number values
  for (int i = 0; i < 6; i++)
  {
    tft.setCursor((minorSizeX - 30), (number[i] + numberSize));
    tft.setTextColor(graphColor);
    tft.setTextSize(1);
    tft.println(val[i]);
  }
}

void graph()
{
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  timeBlock[valuePos] = ((millis() - 4500) / 1000);

  valueBlock[valuePos] = temp;

  if (proDebug)
  {
    Serial.println(timeBlock[valuePos]);
  }

  if (blockPos < 8)
  {
    // print the time
    tft.setCursor((mark[valuePos] - 5), (originY + 16));
    tft.setTextColor(graphColor, WHITE);
    tft.setTextSize(1);
    tft.println(timeBlock[valuePos]);

    // map the value
    locationBlock[valuePos] = map(temp, 0, graphRange, originY, (originY - sizeY));

    // draw point
    tft.fillRect((mark[valuePos] - 1), (locationBlock[valuePos] - 1), markSize, markSize, pointColor);

    // try connecting to previous point
    if (valuePos != 0)
    {
      tft.drawLine(mark[valuePos], locationBlock[valuePos], mark[(valuePos - 1)], locationBlock[(valuePos - 1)], lineColor);
    }

    blockPos++;
  }
  else
  {
    // clear the graph's canvas
    tft.fillRect((originX + 2), (originY - sizeY), sizeX, sizeY, WHITE);

    // map the value - current point
    locationBlock[valuePos] = map(temp, 0, graphRange, originY, (originY - sizeY));

    // draw point - current point
    tft.fillRect((mark[7]), (locationBlock[valuePos] - 1), markSize, markSize, pointColor);

    // draw all points
    for (int i = 0; i < 8; i++)
    {
      tft.fillRect((mark[(blockPos - (i + 1))] - 1), (locationBlock[(valuePos - i)] - 1), markSize, markSize, pointColor);
    }

    // draw all the lines
    for (int i = 0; i < 7; i++)
    {
      tft.drawLine(mark[blockPos - (i + 1)], locationBlock[valuePos - i], mark[blockPos - (i + 2)], locationBlock[valuePos - (i + 1)], lineColor);
    }

    // change time lables
    for (int i = 0; i <= 7; i++)
    {
      tft.setCursor((mark[(7 - i)] - 5), (originY + 16));
      tft.setTextColor(graphColor, WHITE);
      tft.setTextSize(1);
      tft.println(timeBlock[valuePos - i]);
    }
  }

  valuePos++;
}

void setup()
{
  if (proDebug)
  {
    Serial.begin(9600);
    while (!Serial) {};
  }
  sensors.begin();
  tft.reset();
  delay(500);
  uint16_t identifier = tft.readID();
  identifier = 0x9341;

  tft.begin(0x9488);
  tft.setRotation(1);

  drawHome();
  drawGraph();
}

void loop()
{
  graph();
  delay(100);
}

But I want to change the size of the graph, and also where it displays the time that it measured the temperature, I want it to say hours, not seconds, plus I want the time flipped, so zero is on the right side of the screen. How do I do this?

Do you realize a "for() " can be written to begin at a value and subtract from that value until it gets to zero? A "for()" is not always an addition and moving to the right.

@Paul_KD7HB
I'm not sure I follow...

@Paul_KD7HB @madmark2150 @Nick_Pyner

[code]
#include "Adafruit_GFX.h"    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
#include "Universum_TFTColours.h" // Universum library for colours
#include <OneWire.h>
#include <DallasTemperature.h>

MCUFRIEND_kbv tft;

#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 1000

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

// Global variables
int valueBlock[500];
int timeBlock[500];
int locationBlock[500];
int valuePos;
int blockPos;
int temp;

// Editable Variables
bool proDebug = 1;

uint16_t graphColor = LIGHTGREY;
uint16_t pointColor = RED;
uint16_t lineColor = GREEN;

int graphRange = 50;
int markSize = 5;

// Calculate Values
const int numberOfMarks = 12;
const int originX = 27;
const int originY = 293;
const int sizeX = 312;
const int sizeY = 260;
const int deviation = 27;

int boxSize = (sizeX / numberOfMarks);
int mark[] = {(boxSize + deviation), ((boxSize * 2) + deviation), ((boxSize * 3) + deviation), ((boxSize * 4) + deviation), ((boxSize * 5) + deviation), ((boxSize * 6) + deviation), ((boxSize * 7) + deviation), ((boxSize * 8) + deviation), ((boxSize * 9) + deviation), ((boxSize * 10) + deviation), ((boxSize * 11) + deviation), ((boxSize * 12) + deviation)};

const int minorSizeY = (originY + 10);
const int minorSizeX = (originX - 10);

void drawGraph()
{
  tft.fillScreen(BLACK);

  // draw outline
  tft.drawLine(27, 33, 339, 33, LIGHTGREY);
  tft.drawLine(27, 59, 339, 59, LIGHTGREY);
  tft.drawLine(27, 85, 339, 85, LIGHTGREY);
  tft.drawLine(27, 111, 339, 111, LIGHTGREY);
  tft.drawLine(27, 137, 339, 137, LIGHTGREY);
  tft.drawLine(27, 163, 339, 163, LIGHTGREY);
  tft.drawLine(27, 189, 339, 189, LIGHTGREY);
  tft.drawLine(27, 215, 339, 215, LIGHTGREY);
  tft.drawLine(27, 241, 339, 241, LIGHTGREY);
  tft.drawLine(27, 267, 339, 267, LIGHTGREY);
  tft.drawLine(27, 293, 339, 293, LIGHTGREY);

  tft.drawLine(339, 33, 339, 293, LIGHTGREY);
  tft.drawLine(313, 33, 313, 293, LIGHTGREY);
  tft.drawLine(287, 33, 287, 293, LIGHTGREY);
  tft.drawLine(261, 33, 261, 293, LIGHTGREY);
  tft.drawLine(236, 33, 236, 293, LIGHTGREY);
  tft.drawLine(209, 33, 209, 293, LIGHTGREY);
  tft.drawLine(183, 33, 183, 293, LIGHTGREY);
  tft.drawLine(157, 33, 157, 293, LIGHTGREY);
  tft.drawLine(131, 33, 131, 293, LIGHTGREY);
  tft.drawLine(105, 33, 105, 293, LIGHTGREY);
  tft.drawLine(79, 33, 79, 293, LIGHTGREY);
  tft.drawLine(53, 33, 53, 293, LIGHTGREY);
  tft.drawLine(27, 33, 27, 293, LIGHTGREY);

  //draw number value
  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(6, 33);
  tft.print("50");
  tft.print((char)247);
  tft.setCursor(6, 59);
  tft.print("45");
  tft.print((char)247);
  tft.setCursor(6, 85);
  tft.print("40");
  tft.print((char)247);
  tft.setCursor(6, 111);
  tft.print("35");
  tft.print((char)247);
  tft.setCursor(6, 137);
  tft.print("30");
  tft.print((char)247);
  tft.setCursor(6, 163);
  tft.print("25");
  tft.print((char)247);
  tft.setCursor(6, 189);
  tft.print("20");
  tft.print((char)247);
  tft.setCursor(6, 215);
  tft.print("15");
  tft.print((char)247);
  tft.setCursor(6, 241);
  tft.print("10");
  tft.print((char)247);
  tft.setCursor(6, 267);
  tft.print(" 5");
  tft.print((char)247);
  tft.setCursor(6, 290);
  tft.print(" 0");
  tft.print((char)247);
}

void graph()
{
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  timeBlock[valuePos] = ((millis() - 4500) / 1000);

  valueBlock[valuePos] = temp;

  if (proDebug)
  {
    Serial.println(timeBlock[valuePos]);
  }

  if (blockPos < 8)
  {
    tft.setTextSize(1);
    tft.setTextColor(LIGHTGREY);
    tft.setCursor(26, 300);
    tft.print("6");
    tft.setCursor(44, 300);
    tft.print("5.5");
    tft.setCursor(77, 300);
    tft.print("5");
    tft.setCursor(96, 300);
    tft.print("4.5");
    tft.setCursor(128, 300);
    tft.print("4");
    tft.setCursor(148, 300);
    tft.print("3.5");
    tft.setCursor(181, 300);
    tft.print("3");
    tft.setCursor(200, 300);
    tft.print("2.5");
    tft.setCursor(234, 300);
    tft.print("2");
    tft.setCursor(253, 300);
    tft.print("1.5");
    tft.setCursor(285, 300);
    tft.print("1");
    tft.setCursor(305, 300);
    tft.print("0.5");
    tft.setCursor(337, 300);
    tft.print("0");

    // map the value
    locationBlock[valuePos] = map(temp, 0, graphRange, originY, (originY - sizeY));

    // draw point
    tft.fillRect((mark[valuePos] - 2), (locationBlock[valuePos] - 1), markSize, markSize, pointColor);

    // try connecting to previous point
    if (valuePos != 0)
    {
      tft.drawLine(mark[valuePos], locationBlock[valuePos], mark[(valuePos - 1)], locationBlock[(valuePos - 1)], lineColor);
    }

    blockPos++;
  }
  else
  {
    // clear the graph's canvas
    tft.fillRect((originX + 2), (originY - sizeY), sizeX, sizeY, BLACK);

    // draw outline
    tft.drawLine(27, 33, 339, 33, LIGHTGREY);
    tft.drawLine(27, 59, 339, 59, LIGHTGREY);
    tft.drawLine(27, 85, 339, 85, LIGHTGREY);
    tft.drawLine(27, 111, 339, 111, LIGHTGREY);
    tft.drawLine(27, 137, 339, 137, LIGHTGREY);
    tft.drawLine(27, 163, 339, 163, LIGHTGREY);
    tft.drawLine(27, 189, 339, 189, LIGHTGREY);
    tft.drawLine(27, 215, 339, 215, LIGHTGREY);
    tft.drawLine(27, 241, 339, 241, LIGHTGREY);
    tft.drawLine(27, 267, 339, 267, LIGHTGREY);
    tft.drawLine(27, 293, 339, 293, LIGHTGREY);

    tft.drawLine(339, 33, 339, 293, LIGHTGREY);
    tft.drawLine(313, 33, 313, 293, LIGHTGREY);
    tft.drawLine(287, 33, 287, 293, LIGHTGREY);
    tft.drawLine(261, 33, 261, 293, LIGHTGREY);
    tft.drawLine(236, 33, 236, 293, LIGHTGREY);
    tft.drawLine(209, 33, 209, 293, LIGHTGREY);
    tft.drawLine(183, 33, 183, 293, LIGHTGREY);
    tft.drawLine(157, 33, 157, 293, LIGHTGREY);
    tft.drawLine(131, 33, 131, 293, LIGHTGREY);
    tft.drawLine(105, 33, 105, 293, LIGHTGREY);
    tft.drawLine(79, 33, 79, 293, LIGHTGREY);
    tft.drawLine(53, 33, 53, 293, LIGHTGREY);
    tft.drawLine(27, 33, 27, 293, LIGHTGREY);

    // map the value - current point
    locationBlock[valuePos] = map(temp, 0, graphRange, originY, (originY - sizeY));

    // draw point - current point
    tft.fillRect((mark[7]), (locationBlock[valuePos] - 1), markSize, markSize, pointColor);

    // draw all points
    for (int i = 0; i < 8; i++)
    {
      tft.fillRect((mark[(blockPos - (i + 1))] - 1), (locationBlock[(valuePos - i)] - 1), markSize, markSize, pointColor);
    }

    // draw all the lines
    for (int i = 0; i < 7; i++)
    {
      tft.drawLine(mark[blockPos - (i + 1)], locationBlock[valuePos - i], mark[blockPos - (i + 2)], locationBlock[valuePos - (i + 1)], lineColor);
    }
  }

  valuePos++;
}

void setup()
{
  if (proDebug)
  {
    Serial.begin(9600);
    while (!Serial) {};
  }
  sensors.begin();
  tft.reset();
  delay(500);
  tft.begin(0x9488);
  tft.setRotation(1);
  drawGraph();
}

void loop()
{
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.fillRect(370, 5, 200, 200, BLACK);
  tft.setCursor(370, 5);
  tft.print(sensors.getTempCByIndex(0));
  graph();
  delay(1000);
}
[/code]

When I change the proDebug to 1 as in the above code, my Serial monitor returns this:

-30412
-30410
0
2
3
5
7
8
10
11
13
15
16
18
20
21
23
25
26
28
30
31

I think this is the time??
But what is the -30412, -30410??

The main question I have is where do I set where the first point is drawn?

    // draw point
    tft.fillRect((mark[valuePos] - 2), (locationBlock[valuePos] - 1), markSize, markSize, pointColor);

    // map the value - current point
    locationBlock[valuePos] = map(temp, 0, graphRange, originY, (originY - sizeY));

    // draw point - current point
    tft.fillRect((mark[7]), (locationBlock[valuePos] - 1), markSize, markSize, pointColor);

    // draw all points
    for (int i = 0; i < 8; i++)
    {
      tft.fillRect((mark[(blockPos - (i + 1))] - 1), (locationBlock[(valuePos - i)] - 1), markSize, markSize, pointColor);
    }

From what I can work out, I think this is where it decides the place to draw the points (in void graph()), but I don't know where to edit it to choose where on the X plane I draw it.

@Nick_Pyner @Paul_KD7HB @madmark2150
I have figured out one issue:

#include "Adafruit_GFX.h"    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
#include "Universum_TFTColours.h" // Universum library for colours
#include <OneWire.h>
#include <DallasTemperature.h>

MCUFRIEND_kbv tft;

#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 1000

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

// Global variables
int valueBlock[500];
int timeBlock[500];
int locationBlock[500];
int valuePos;
int blockPos;
int temp;

// Editable Variables
bool proDebug = 1;

uint16_t graphColor = LIGHTGREY;
uint16_t pointColor = RED;
uint16_t lineColor = GREEN;

int graphRange = 50;
int markSize = 2;

// Calculate Values
const int numberOfMarks = 12;
const int originX = 27;
const int originY = 293;
const int sizeX = 312;
const int sizeY = 260;
const int deviation = 27;

int boxSize = (sizeX / numberOfMarks);
int mark[] = {(boxSize + deviation), ((boxSize * 2) + deviation), ((boxSize * 3) + deviation), ((boxSize * 4) + deviation), ((boxSize * 5) + deviation), ((boxSize * 6) + deviation), ((boxSize * 7) + deviation), ((boxSize * 8) + deviation), ((boxSize * 9) + deviation), ((boxSize * 10) + deviation), ((boxSize * 11) + deviation), ((boxSize * 12) + deviation)};

void drawGraph()
{
  tft.fillScreen(BLACK);

  // draw outline
  tft.drawLine(27, 33, 339, 33, LIGHTGREY);
  tft.drawLine(27, 59, 339, 59, LIGHTGREY);
  tft.drawLine(27, 85, 339, 85, LIGHTGREY);
  tft.drawLine(27, 111, 339, 111, LIGHTGREY);
  tft.drawLine(27, 137, 339, 137, LIGHTGREY);
  tft.drawLine(27, 163, 339, 163, LIGHTGREY);
  tft.drawLine(27, 189, 339, 189, LIGHTGREY);
  tft.drawLine(27, 215, 339, 215, LIGHTGREY);
  tft.drawLine(27, 241, 339, 241, LIGHTGREY);
  tft.drawLine(27, 267, 339, 267, LIGHTGREY);
  tft.drawLine(27, 293, 339, 293, LIGHTGREY);

  tft.drawLine(339, 33, 339, 293, LIGHTGREY);
  tft.drawLine(313, 33, 313, 293, LIGHTGREY);
  tft.drawLine(287, 33, 287, 293, LIGHTGREY);
  tft.drawLine(261, 33, 261, 293, LIGHTGREY);
  tft.drawLine(236, 33, 236, 293, LIGHTGREY);
  tft.drawLine(209, 33, 209, 293, LIGHTGREY);
  tft.drawLine(183, 33, 183, 293, LIGHTGREY);
  tft.drawLine(157, 33, 157, 293, LIGHTGREY);
  tft.drawLine(131, 33, 131, 293, LIGHTGREY);
  tft.drawLine(105, 33, 105, 293, LIGHTGREY);
  tft.drawLine(79, 33, 79, 293, LIGHTGREY);
  tft.drawLine(53, 33, 53, 293, LIGHTGREY);
  tft.drawLine(27, 33, 27, 293, LIGHTGREY);

  //draw number value
  tft.setTextSize(1);
  tft.setTextColor(LIGHTGREY);
  tft.setCursor(6, 33);
  tft.print("50");
  tft.print((char)247);
  tft.setCursor(6, 59);
  tft.print("45");
  tft.print((char)247);
  tft.setCursor(6, 85);
  tft.print("40");
  tft.print((char)247);
  tft.setCursor(6, 111);
  tft.print("35");
  tft.print((char)247);
  tft.setCursor(6, 137);
  tft.print("30");
  tft.print((char)247);
  tft.setCursor(6, 163);
  tft.print("25");
  tft.print((char)247);
  tft.setCursor(6, 189);
  tft.print("20");
  tft.print((char)247);
  tft.setCursor(6, 215);
  tft.print("15");
  tft.print((char)247);
  tft.setCursor(6, 241);
  tft.print("10");
  tft.print((char)247);
  tft.setCursor(6, 267);
  tft.print(" 5");
  tft.print((char)247);
  tft.setCursor(6, 290);
  tft.print(" 0");
  tft.print((char)247);
}

void graph()
{
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  timeBlock[valuePos] = ((millis() - 4500) / 1000);

  valueBlock[valuePos] = temp;

  if (proDebug)
  {
    Serial.println(timeBlock[valuePos]);
  }

  if (blockPos < 12)
  {
    tft.setTextSize(1);
    tft.setTextColor(LIGHTGREY);
    tft.setCursor(26, 300);
    tft.print("6");
    tft.setCursor(44, 300);
    tft.print("5.5");
    tft.setCursor(77, 300);
    tft.print("5");
    tft.setCursor(96, 300);
    tft.print("4.5");
    tft.setCursor(128, 300);
    tft.print("4");
    tft.setCursor(148, 300);
    tft.print("3.5");
    tft.setCursor(181, 300);
    tft.print("3");
    tft.setCursor(200, 300);
    tft.print("2.5");
    tft.setCursor(234, 300);
    tft.print("2");
    tft.setCursor(253, 300);
    tft.print("1.5");
    tft.setCursor(285, 300);
    tft.print("1");
    tft.setCursor(305, 300);
    tft.print("0.5");
    tft.setCursor(337, 300);
    tft.print("0");

    // map the value               temp, 0, 50, 293, 33
    locationBlock[valuePos] = map(temp, 0, graphRange, originY, (originY - sizeY));

    // draw point
    tft.fillRect((mark[valuePos] - 27), (locationBlock[valuePos] - 1), markSize, markSize, pointColor);

    // try connecting to previous point
    if (valuePos != 0)
    {
      tft.drawLine(mark[valuePos], locationBlock[valuePos], mark[(valuePos - 1)], locationBlock[(valuePos - 1)], lineColor);
    }

    blockPos++;
  }
  else
  {
    // clear the graph's canvas
    tft.fillRect((originX + 1), (originY - sizeY), sizeX + 1, sizeY, BLACK);

    // draw outline
    tft.drawLine(27, 33, 339, 33, LIGHTGREY);
    tft.drawLine(27, 59, 339, 59, LIGHTGREY);
    tft.drawLine(27, 85, 339, 85, LIGHTGREY);
    tft.drawLine(27, 111, 339, 111, LIGHTGREY);
    tft.drawLine(27, 137, 339, 137, LIGHTGREY);
    tft.drawLine(27, 163, 339, 163, LIGHTGREY);
    tft.drawLine(27, 189, 339, 189, LIGHTGREY);
    tft.drawLine(27, 215, 339, 215, LIGHTGREY);
    tft.drawLine(27, 241, 339, 241, LIGHTGREY);
    tft.drawLine(27, 267, 339, 267, LIGHTGREY);
    tft.drawLine(27, 293, 339, 293, LIGHTGREY);

    tft.drawLine(339, 33, 339, 293, LIGHTGREY);
    tft.drawLine(313, 33, 313, 293, LIGHTGREY);
    tft.drawLine(287, 33, 287, 293, LIGHTGREY);
    tft.drawLine(261, 33, 261, 293, LIGHTGREY);
    tft.drawLine(236, 33, 236, 293, LIGHTGREY);
    tft.drawLine(209, 33, 209, 293, LIGHTGREY);
    tft.drawLine(183, 33, 183, 293, LIGHTGREY);
    tft.drawLine(157, 33, 157, 293, LIGHTGREY);
    tft.drawLine(131, 33, 131, 293, LIGHTGREY);
    tft.drawLine(105, 33, 105, 293, LIGHTGREY);
    tft.drawLine(79, 33, 79, 293, LIGHTGREY);
    tft.drawLine(53, 33, 53, 293, LIGHTGREY);
    tft.drawLine(27, 33, 27, 293, LIGHTGREY);

    // map the value - current point
    locationBlock[valuePos] = map(temp, 0, graphRange, originY, (originY - sizeY));

    // draw point - current point
    tft.fillRect((mark[12]), (locationBlock[valuePos] - 1), (markSize / 2), (markSize / 2), pointColor);

    // draw all points
    for (int i = 1; i < 12; i++)
    {
      tft.fillRect((mark[(blockPos - (i + 1))] - 1), (locationBlock[(valuePos - i)] - 1), markSize, markSize, pointColor);
    }

    // draw all the lines
    for (int i = 0; i < 11; i++)
    {
      tft.drawLine(mark[blockPos - (i + 1)], locationBlock[valuePos - i], mark[blockPos - (i + 2)], locationBlock[valuePos - (i + 1)], lineColor);
    }
  }

  valuePos++;
}

void setup()
{
  if (proDebug)
  {
    Serial.begin(9600);
    while (!Serial) {};
  }
  sensors.begin();
  tft.reset();
  delay(500);
  tft.begin(0x9488);
  tft.setRotation(1);
  drawGraph();
}

void loop()
{
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.fillRect(370, 5, 200, 100, BLACK);
  tft.setCursor(370, 5);
  tft.print(sensors.getTempCByIndex(0));
  graph();
}

It now looks like this:


But there is a strange red dot and a missing green line:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.