Average of a broken line displayed on an ILI9341

Average height of a broken line displayed on an ILI9341

IntermediateFull instructions provided-120 minutes63
Average of a broken line displayed on an ILI9341

Things used in this project

Hardware components

ILI9341
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Story

Read more

Schematics

Schematics

Code

CODE

Arduino
The code for the average height that is measured from a broken line displayed on an ILI9341
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_DC A3
#define TFT_CS A5
#define  TFT_RST A4
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

uint16_t ox = 0, oy = 0;
int ave = 0, avec = 0, avet = 0;

////////////////////////////////////////////////////////////////
void aveg(void)
{ int z = 0;
  Serial.println(ave);
  Serial.println(avec);
  avet = ave / avec;
  Serial.println(avet);
  avet = avet * 32;

  for (int i = 0; i < 24; i++) {

    for (uint16_t a = 0; a < 3; a++) {
      tft.drawLine(avet + a, z, avet + a, z + 10, 0xFB21);
    } // thick
    for (uint16_t a = 0; a < 2; a++) {
      tft.drawLine(avet - a, z, avet - a, z + 10, 0xFB21);
    }
    delay(100);
    z = z + 20;
  }
}
//////////////////////////////////////////////////////////////////
void dchart_10x10(uint16_t nx, uint16_t ny) {
  ave += nx;
  avec++;
  nx = nx * 32;
  ny = ny * 48;
  tft.drawCircle(nx, ny, 10, 0x0517);
  tft.drawCircle(nx, ny, 9, 0x0517);
  tft.fillCircle(nx, ny, 7, 0x0517);
  delay(100);
  ox = nx;
  oy = ny;
}
///////////////////////////////////////////////////////////////////////
void dotchart_10x10(uint16_t nx, uint16_t ny) {
  ave += nx;
  avec++;
  nx = nx * 32;
  ny = ny * 48;
  int plus = 0;
  float fplus = 0;
  int sign = 0;
  int y = 0, x = 0;
  y = oy; x = ox;
  float xmines, ymines;
  xmines = nx - ox;
  ymines = ny - oy;
  if (ox > nx) {
    xmines = ox - nx;
    sign = 1;
  }
  else
    sign = 0;

  for (int a = 0; a < (ny - oy); a++)
  {
    fplus += xmines / ymines;
    plus = fplus;
    if (sign == 1)
      tft.drawFastHLine(0, y, x - plus, 0xBFDF);
    else
      tft.drawFastHLine(0, y, x + plus, 0xBFDF);
    y++;
    delay(5);
  }

  for (uint16_t a = 0; a < 2; a++) {
    tft.drawLine(ox + a, oy, nx + a, ny, 0x01E8);
  } // thick
  for (uint16_t a = 0; a < 2; a++) {
    tft.drawLine(ox, oy + a, nx, ny + a, 0x01E8);
  }


  ox = nx;
  oy = ny;
}
////////////////////////////////////////////////////////////////////

void setup() {
  Serial.begin(9600);
  tft.begin();
}

void loop() {
  tft.invertDisplay(true);
  tft.fillScreen(0xffff);

  dotchart_10x10(3, 0);
  dotchart_10x10(2, 1);
  dotchart_10x10(4, 2);
  dotchart_10x10(4, 3);
  dotchart_10x10(5, 4);
  dotchart_10x10(3, 5);
  dotchart_10x10(6, 6);
  dotchart_10x10(7, 7);
  dotchart_10x10(9, 8);
  dotchart_10x10(8, 9);
  dotchart_10x10(10, 10);

  dchart_10x10(3, 0);
  dchart_10x10(2, 1);
  dchart_10x10(4, 2);
  dchart_10x10(4, 3);
  dchart_10x10(5, 4);
  dchart_10x10(3, 5);
  dchart_10x10(6, 6);
  dchart_10x10(7, 7);
  dchart_10x10(9, 8);
  dchart_10x10(8, 9);
  dchart_10x10(10, 10);


  tft.setRotation(1);
  tft.setTextSize(2);
  tft.setTextColor(0x01E8);
  tft.setCursor(20, 20);
  tft.print("Average");

  int dl = 20;
  for (int i = 0; i < 6; i++) {
    for (uint16_t a = 0; a < 3; a++) {
      tft.drawLine(dl, 40 + a, dl + 10, 40 + a, 0xFB21);
    }
    dl += 16;
  }

  tft.setRotation(0);
  aveg();

  while (1);
}

Credits

Projects with Arduino (pierre  @ clatot.eu)

Projects with Arduino (pierre @ clatot.eu)

4 projects • 1 follower

Comments