jg53fn55
Published © GPL3+

Digital Barometer

Barometer/thermometer/humiditymeter with ten 10-segment led bar

IntermediateShowcase (no instructions)796
Digital Barometer

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Shift Register- Serial to Parallel
Texas Instruments Shift Register- Serial to Parallel
SN74595
×4
MyOctopus i2c Barometric Air Pressure Sensor BMP280
MyOctopus i2c Barometric Air Pressure Sensor BMP280
×1
Grove - I2C High Accuracy Temp&Humi Sensor (SHT35)
Seeed Studio Grove - I2C High Accuracy Temp&Humi Sensor (SHT35)
or HCT31
×1
FPGA Configuration Memory, EEPROM
FPGA Configuration Memory, EEPROM
×1
TFT Touchscreen, 320x240
TFT Touchscreen, 320x240
TFT ILI 9341
×1
Toggle Switch, (On)-Off-(On)
Toggle Switch, (On)-Off-(On)
×4
10 LEDs Bar Array, Green
10 LEDs Bar Array, Green
×10
Resistor 220 ohm
Resistor 220 ohm
×10

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Barometer

Barometer/thermometer/humiditymeter

Code

Barometer

Arduino
Barometer/thermometer/humiditymeter
//**************************************************************************
#include <Adafruit_BMP085.h>
#include "SHT31.h"
#include <SPI.h>
#include <Wire.h>
#include <AT24CX.h>  // eeprom 256kbit
#include <Adafruit_GFX.h>    // Include core graphics library
#include <Adafruit_ILI9341.h> // Include Adafruit_ILI9341 library to drive the display
//#define TFT_DC 10
//#define TFT_RST 9
//#define TFT_CS 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(8, 10, 9);
#define I2C_ADDRESS 0x77
#define SHT31_ADDRESS   0x44
#define BLACK    0x0000
#define BLUE     0x001F
#define RED      0xF800
#define GREEN    0x07E0
#define YELLOW   0xFFE0
#define WHITE    0xFFFF
Adafruit_BMP085 bmp;
AT24CX mem;
SHT31 sht;
byte dataPin = 2;
byte latchPin = 3;
byte clockPin = 4;
byte TFTL = 7;
byte LedRange = 6;// schaalverlichting
byte SW1 = A0;
byte SW2 = A1;
byte SW3 = A2;
byte SW4 = A3;
byte LB;
byte HB;
int BR;
int TM;
int HG;
byte uur;
byte minuut;
byte seconde;
byte xy[192];
byte testH;
byte testL;
float Temp;
float Temp1;
float Hygro;
float Hygro1;
float Baro;
byte test1;
byte test2;
byte test3;
byte test4;
byte ddd[17];
unsigned long currentMillis;
long interval = 30000;
long previousMillis = 0;
unsigned long BcurrentMillis;
long Binterval = 900000;
long BpreviousMillis = 0;
unsigned long TijdcurrentMillis;
long Tijdinterval = 86400000;
long TijdpreviousMillis = 0;
byte rij1[11] = { 0, 2, 4, 8, 16, 32, 0, 0, 0, 0, 0}; // dotmode
byte rij2[11] = { 32, 0, 0, 0, 0, 0, 2, 4, 8, 16, 0}; // dotmode
byte kolom1BM[12] = { 253, 251, 247, 239, 223, 255, 255, 255, 255, 255, 255, 255}; // dot en barmode
byte kolom2BM[12] = { 255, 255, 255, 255, 255, 253, 251, 247, 239, 223, 223, 255}; // dot en barmode
byte rij1BM[11] = { 62, 2, 6, 14, 30, 62, 62, 62, 62, 62, 0}; // barmode
byte rij2BM[11] = { 62, 0, 0, 0, 0, 0, 2, 6, 14, 30, 0}; // barmode
//---------------------------------------------------------------------
void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(TFTL, OUTPUT);
  pinMode(LedRange, OUTPUT);
  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
  pinMode(SW3, INPUT_PULLUP);
  pinMode(SW4, INPUT_PULLUP);
  digitalWrite(TFTL, HIGH);

  Serial.begin(9600);
  Wire.begin();
  sht.begin(SHT31_ADDRESS);

  if (!bmp.begin(I2C_ADDRESS)) {
    //Serial.println("Could not find a valid BMP085 sensor, check wiring!");
    while (1) {}
  }
  delay (1000);
  SensorLDUitlezen();
  tft.begin();  // Initialize display

  tft.fillScreen(BLACK);  // Fill screen with black

  tft.setRotation(1);  // Set orientation of the display. Values are from 0 to 3. If not declared, orientation would be 0,
  // which is portrait mode.

  tft.setTextWrap(false);  // By default, long lines of text are set to automatically wrap back to the leftmost column.
  // To override this behavior (so text will run off the right side of the display - useful for
  // scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
  // with setTextWrap(true).
  tft.setTextSize(3);  // Set text size. Goes from 0 (the smallest) to 20 (very big)

  //  tft.backlight(off);
  BarCode(0, 10, 11);
  digitalWrite(LedRange, LOW);
  Bartest();
  delay(1000);
  float2byte (1200, 100, 0);
  float2byte (1202, 0, 0);
  float2byte (2200, 100, 0);
  float2byte (2202, 0, 0);

  /*
     for (int x = 2000 ; x < 2188; x += 2) {
     mem.write(x, 50);
     mem.write(x + 1, 0);
     }
     for (int x = 1000 ; x < 1188; x += 2) {
     mem.write(x, 20);
     mem.write(x + 1, 0);
     }
    for (int x = 0 ; x < 188; x += 2) {
     mem.write(x, 50);
     mem.write(x + 1, 0);
     }
  */


  //float2byte(200, 972.84, 950);


  //float2byte(202, 1025.46, 950);



}

//---------------------------------------------------------------------------------
void loop() {

  byte test;
  test1 = digitalRead(SW1);
  test2 = digitalRead(SW2);
  test3 = digitalRead(SW3);
  test4 = digitalRead(SW4);
  test = test4 * 8;
  test += test3 * 4;
  test += test2 * 2;
  test += test1;


  switch (test) {
    case 0 : //0000
      if (ddd[0] == 0)
      {
        dddInstellen(0);
        tft.begin();
        digitalWrite(TFTL, LOW);
        digitalWrite(LedRange, LOW);
        tft.fillScreen(BLACK);
        tft.setRotation(1);
        tft.setTextWrap(false);
        BarCode(0, 10, 11); // led array uit

      }
      break;
    //================================

    case 1 : //0001
      if (ddd[1] == 0)
      {
        dddInstellen(1);
        CHBtekst();
      }
      break;
    //================================
    case 2 : // 0010 barmode
      if (ddd[2] == 0)
      {
        dddInstellen(2);
        Sensortekst(950, Baro, 1050, "Sch.: 10 mBar     ", GREEN);
      }
      SensorW( Baro, 950, 1);
      // bereik = 950 - 1050 mB
      // 1 led = 1 mB
      break;
    //=============================
    case 3 : // 0011  barmode
      if (ddd[3] == 0)
      {
        dddInstellen(3);
        Sensortekst(0, Temp, 50, "Sch.: 5 gr. C   ", RED);
      }
      SensorW( Temp, 0, 2);

      // bereik = 0 - 50 C
      // 5 graad = 10 led
      break;
    //======================================
    case 4 : // 0100  barmode
      if (ddd[4] == 0)
      {
        dddInstellen(4);
        Sensortekst(0, Hygro, 100, "Sch.: 10 %        ", BLUE);
      }
      SensorW( Hygro, 0, 1);

      // bereik = 0 - 100 %
      break;
    //===================================
    case 5 : // 0101 trend past 24 hours
      if (ddd[5] == 0)
      {
        dddInstellen(5);
        String Tekst;
        Tekst = Baro;
        Tekst = "Baro = " + Tekst;
        Grafiek(0, 188, 950, Tekst, "x"); //startadres,stopadres, waardeverekening baro
      }
      SensorW( Baro, 950, 1);
      break;
    //==========================
    case 6 : // 0110 trend past 24 hours
      if (ddd[6] == 0)
      {
        dddInstellen(6);
        String Tekst;
        Tekst = Temp;
        Tekst = "Temp = " + Tekst;
        Grafiek(1000, 1188, 0, Tekst, "x"); //startadres,stopadres, waardeverekening temp
      }
      SensorW( Temp, 0, 2);
      break;
    //==================================
    case 7 : // 0111 trend past 24 hours
      if (ddd[7] == 0)
      {
        dddInstellen(7);
        String Tekst;
        Tekst = Hygro;
        Tekst = "Hygro = " + Tekst;
        Grafiek(2000, 2188, 0, Tekst, "x"); //startadres,stopadres, waardeverekening hygro
      }
      SensorW( Hygro, 0, 1);
      break;
    //==================================
    case 8 : // 1000 airpressure trend
      if (ddd[8] == 0)
      {
        BarCode(0, 10, 11);
        digitalWrite(LedRange, LOW);
        dddInstellen(8);
        WeerTrend();
      }
      break;
    //===================================
    case 9 : // 1001 max min temperature
      if (ddd[9] == 0)
      {
        BarCode(0, 10, 11);
        digitalWrite(LedRange, LOW);
        dddInstellen(9);
        THData();
      }
      break;
    //==================================
    case 10 : // 1010  dotmode
      if (ddd[10] == 0)
      {
        dddInstellen(10);
        Sensortekst(950, Baro, 1050, "Sch.: 10 mBar     ", GREEN);
      }
      SensorD( Baro, 950, 1);
      // bereik = 950 - 1050 mB
      // 1 led = 1 mB
      break;

    //=============================
    case 11 : // 1011  dotmode
      if (ddd[11] == 0)
      {
        dddInstellen(11);
        Sensortekst(0, Temp, 50, "Sch.: 5 gr. C   ", RED);
      }
      SensorD( Temp, 0, 2);

      // bereik = 0 - 50 C
      // 5 graad = 10 led
      break;
    //======================================
    case 12 : // 1100  dotmode
      if (ddd[12] == 0)
      {
        dddInstellen(12);
        Sensortekst(0, Hygro, 100, "Sch.: 10 %        ", BLUE);
      }
      SensorD( Hygro, 0, 1);

      // bereik = 0 - 100 %
      break;
    //===================================
    case 13 : // 1101 zoommode x 10
      if (ddd[13] == 0)

      {
        dddInstellen(13);
        //String Tekst;
        //Tekst = Baro;
        //Tekst = "Baro = " + Tekst;
        //Grafiek(0, 188, 950, Tekst, "B"); //startadres,stopadres, waardeverekening baro

        if (Baro > 950 & Baro <= 960) {
          BR = 955;
        }
        else if (Baro > 960 & Baro <= 970) {
          BR = 965;
        }
        else if (Baro > 970 & Baro <= 980) {
          BR = 975;
        }
        else if (Baro > 980 & Baro <= 990) {
          BR = 985;
        }
        else if (Baro > 990 & Baro <= 1000) {
          BR = 995;
        }
        else if (Baro > 1000 & Baro <= 1010) {
          BR = 1005;
        }
        else if (Baro > 1010 & Baro <= 1020) {
          BR = 1015;
        }
        else if (Baro > 1020 & Baro <= 1030) {
          BR = 1025;
        }
        else if (Baro > 1030 & Baro <= 1040) {
          BR = 1035;
        }
        else if (Baro > 1040 & Baro <= 1050) {
          BR = 1045;
        }
        Sensortekst(BR - 5, Baro, BR + 5, "Sch.: 1 mBar     ", GREEN);
      }

      SensorW( Baro, BR - 5, 10);
      break;
    //==========================
    case 14 : // 1110 zoommode x 5
      if (ddd[14] == 0)
      {
        dddInstellen(14);
        // String Tekst;
        // Tekst = Temp;
        // Tekst = "Temp = " + Tekst;
        //Grafiek(1000, 1188, 0, Tekst, "T"); //startadres,stopadres, waardeverekening temp
        if (Temp > 0 & Temp < 10) {
          TM = 5;
        }
        else if (Temp > 10 & Temp <= 20) {
          TM = 15;
        }
        else if (Temp > 20 & Temp <= 30) {
          TM = 25;
        }
        else if (Temp > 30 & Temp <= 40) {
          TM = 35;
        }
        else if (Temp > 40 & Temp <= 50) {
          TM = 45;
        }
        Sensortekst(TM - 5, Temp, TM + 5, "Sch.: 1 gr. C   ", RED);
      }
      SensorW( Temp, TM - 5, 10);
      break;
    //==================================
    case 15 : // 1111
      if (ddd[15] == 0)
      {
        dddInstellen(15);
        //String Tekst;
        //Tekst = Hygro;
        //Tekst = "Hygro = " + Tekst;
        //Grafiek(2000, 2188, 0, Tekst, "B"); //startadres,stopadres, waardeverekening hygro
        if (Hygro > 0 & Hygro < 10) {
          HG = 5;
        }
        else if (Hygro > 10 & Hygro <= 20) {
          HG = 15;
        }
        else if (Hygro > 20 & Hygro <= 30) {
          HG = 25;
        }
        else if (Hygro > 30 & Hygro <= 40) {
          HG = 35;
        }
        else if (Hygro > 40 & Hygro <= 50) {
          HG = 45;
        }
        else if (Hygro > 50 & Hygro <= 60) {
          HG = 55;
        }
        else if (Hygro > 60 & Hygro <= 70) {
          HG = 65;
        }
        else if (Hygro > 70 & Hygro <= 80) {
          HG = 75;
        }
        else if (Hygro > 80 & Hygro <= 80) {
          HG = 85;
        }
        else if (Hygro > 90 & Hygro <= 100) {
          HG = 95;
        }

        Sensortekst(HG - 5, Hygro, HG + 5, "Sch.: 10 %        ", BLUE);
      }

      SensorW( Hygro, HG - 5, 10);
      break;
      //==================================
  }


  //=============een keer per dag max en min van temp en hygro resetten ===============
  TijdcurrentMillis = millis();
  if (TijdcurrentMillis - TijdpreviousMillis > Tijdinterval)
  {
    TijdpreviousMillis = TijdcurrentMillis;
    float2byte (1200, Temp, 0);
    float2byte (1202, Temp, 0);
    float2byte (2200, Hygro, 0);
    float2byte (2202, Hygro, 0);
  }

  //============een keer per 30 seconden sensor uitlezen ===========================
  currentMillis = millis();
  if (currentMillis - previousMillis > interval)
  {
    previousMillis = currentMillis;
    dddInstellen(16);
    SensorLDUitlezen();

  }

  //============= een keer per kwartier data naar eeprom =============

  BcurrentMillis = millis();
  if (BcurrentMillis - BpreviousMillis > Binterval)
  {
    BpreviousMillis = BcurrentMillis;

    //============== baro ======================
    float2byte (190, Baro, 950);
    dataopslaan(0, 190);

    // for (int i = 0; i < sizeof(xy); i++) {
    //   byte sb = mem.read(0 + i);
    //  Serial.print("[");
    //   Serial.print(0 + i);
    // Serial.print("] = ");
    // Serial.println(sb);
    //}

    //================= temp =================
    float2byte (1190, Temp, 0);
    dataopslaan(1000, 1190);

    //================= hygro =================
    float2byte (2190, Hygro, 0);
    dataopslaan(2000, 2190);

    //for (int i = 0; i < sizeof(xy); i++)
    // {
    //  byte sb = mem.read(2000 + i);
    //  Serial.print("[");
    // Serial.print(2000 + i);
    // Serial.print("] = ");
    //  Serial.println(sb);
    // }
  }
  // ======================================


}// einde void loop
//-----------------------------------------------------------------------------
void dataopslaan(int startA, int stopA) {
  byte tt;
  int xx = 0;
  for (int addr = startA; addr < stopA; addr += 2)
  {
    tt = mem.read(addr + 2);
    xy[xx] = tt;
    tt = mem.read(addr + 3);
    xy[xx + 1] = tt;
    xx += 2;
  }
  mem.write(startA, (byte*)xy, sizeof(xy));
}
//-----------------------------------------------------------------------------
void float2byte (int adres, float sw, float af) {
  int sw1;
  sw1 = sw;
  testH = sw - af;
  testL = (sw - sw1) * 100;
  mem.write(adres, testH);
  mem.write(adres + 1, testL);

}
//-------------------------------------------------------------------
float byte2float ( int adres, float bij) {
  float SW;
  float ttl;
  testH = mem.read(adres);
  testL = mem.read(adres + 1);
  ttl = testL;
  SW = testH + ( ttl / 100);
  SW += bij;
  return SW;
}
//--------------------------------------------------------------------------------
void dddInstellen(byte een) {
  for (byte x = 0 ; x < 16; x++)
  {
    ddd[x] = 0;// alles op nul zetten
  }
  ddd[een] = 1;// 1 van de 16 op 1 zetten, zodat de routine 1 maal doorlopen wordt
}
// ---------------------------------------------------------------------

void SensorLDUitlezen() {
  float dummy;
  dummy = bmp.readTemperature();
  Baro = bmp.readPressure();
  Baro = (Baro / 100);



  sht.read();

  Temp = sht.getTemperature();
  Hygro = sht.getHumidity();
  Temp = Temp - 1 ;
  maxmin(200, Baro, 950);
  maxmin(1200, Temp, 0);
  maxmin(2200, Hygro, 0);

  //Serial.print("baro min = ");
  //Serial.println(Minimum);
  //Serial.print("baro max = ");
  //Serial.println(Maximum);
}
//-------------------------------------------------------------------------------------------
void maxmin(int startA, float Sensor, float erbij) {
  float waarde;

  waarde = byte2float (startA, erbij);// adres, waarde erbij,= minimum
  if (Sensor < waarde) {
    float2byte(startA, Sensor, erbij);
  }
  waarde = byte2float (startA + 2, erbij); //adres, waarde erbij, = maximum
  if (Sensor > waarde) {
    float2byte(startA + 2, Sensor, erbij);
  }
}
//--------------------------------------------------------------------------------------------
void CHBtekst() {
  BarCode(0, 10, 11);
  digitalWrite(LedRange, LOW);
  String Temp1;
  String Hygro1;
  String Baro1;
  digitalWrite(TFTL, HIGH);
  Temp1 = String(Temp);
  Temp1 += " C           ";
  Hygro1 = String(Hygro);
  Hygro1 += " %          ";
  Baro1 = String(Baro);
  Baro1 += " mB          ";
  tft.fillScreen(BLACK);
  tft.setTextSize(3);
  tft.setTextColor(RED, 0);
  tft.setCursor(10, 50);  // Set position (x,y)
  tft.println("Temp: ");  // Print a text or value
  tft.setCursor(120, 50);  // Set position (x,y)
  tft.println(Temp1);  // Print a text or value

  tft.setTextColor(BLUE, 0); // blauw Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 100);  // Set position (x,y)
  tft.println("LV  :                      ");  // Print a text or value
  tft.setCursor(120, 100);  // Set position (x,y)
  tft.println(Hygro1);  // Print a text or value

  tft.setTextColor(GREEN, 0); // groen Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 150);  // Set position (x,y)
  tft.println("Atm : ");  // Print a text or value
  tft.setCursor(120, 150);  // Set position (x,y)
  tft.println(Baro1); // Print a text or value

  float test ;
  test = (BcurrentMillis - BpreviousMillis);

  test = test / 900000;
  //Serial.print("test : ");
  //Serial.println(BcurrentMillis);
  // Serial.println(BpreviousMillis);
  // Serial.println(test);



  for (byte x = 0 ; x < 11; x++) {
    tft.drawLine((x * 27) + 20, 210, (x * 27) + 20, 220, RED);// uurlijnen
  }
  tft.drawLine(20, 214, (test * 270) + 20, 214, RED);
  tft.drawLine(20, 215, (test * 270) + 20, 215, RED);
  tft.drawLine(20, 216, (test * 270) + 20, 216, RED);
}


//----------------------------------------------------------
void Sensortekst(int Min, float SW, int Max, String Tekst1, int kleur) {
  String Sensor;
  String Min1;
  String Max1;
  Sensor = SW;
  Sensor += "            ";
  Min1 = Min;
  Min1 += "              ";
  Max1 = Max;
  Max1 += "              ";
  digitalWrite(TFTL, HIGH);
  digitalWrite(LedRange, HIGH);
  tft.fillScreen(BLACK);
  tft.setTextSize(3);
  if (kleur == GREEN) {
    tft.setTextColor(GREEN, 0); // rood Set color of text. First is the color of text and after is color of background
    tft.setCursor(10, 0);  // Set position (x,y)
    tft.println("--- Barometer --- ");
  }
  else if (kleur == RED) {
    tft.setTextColor(kleur, 0); // rood Set color of text. First is the color of text and after is color of background
    tft.setCursor(10, 0);  // Set position (x,y)
    tft.println("-- Thermometer --  ");
  }
  else if (kleur == BLUE) {
    tft.setTextColor(kleur, 0); // rood Set color of text. First is the color of text and after is color of background
    tft.setCursor(10, 0);  // Set position (x,y)
    tft.println("-- Hygrometer --  ");
  }

  tft.setTextColor(kleur, 0); // rood Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 50);  // Set position (x,y)
  tft.println("Max : ");  // Print a text or value
  tft.setCursor(120, 50);  // Set position (x,y)
  tft.println(Max1);  // Print a text or value



  //tft.setTextColor(kleur, 0); // blauw Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 100);  // Set position (x,y)
  tft.println("Nu  : ");  // Print a text or value
  tft.setCursor(120, 100);  // Set position (x,y)
  tft.println(Sensor);  // Print a text or value


  //tft.setTextColor(kleur, 0); // groen Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 150);  // Set position (x,y)
  tft.println("Min : ");  // Print a text or value
  tft.setCursor(120, 150);  // Set position (x,y)
  tft.println(Min1);  // Print a text or value

  //tft.setTextColor(kleur, 0);
  tft.setCursor(10, 200);  // Set position (x,y)
  tft.println(Tekst1);  // Print a text or valu

}

//----------------------------------------------------------
void Sensor(float SW, int S1, float S2 ) {
  byte SW1;
  digitalWrite(LedRange, HIGH);
  SW1 = ((SW - S1) * S2) + 0.5;
  LB = Eenh(SW1);
  HB = Tiental(SW1);
}
//----------------------------------------------------------
void SensorW(float SW, int S1, float S2 ) {
  Sensor(SW, S1, S2);
  if (LB == 0 & HB == 0) {
    BarCode(0, 10, 11);
  }
  else {
    BarMode(LB, HB);
  }
}
//------------------------------------------------------------
void SensorD (float SW, int S1, float S2 )  {
  Sensor(SW, S1, S2);
  if (LB == 0 & HB == 0) {
    BarCode(0, 10, 11);
  }
  else {
    DotMode(LB, HB);
  }
}
//------------------------------------------------------------
void Grafiek(int StartA, int StopA, float ErBij, String text, String ID7) {
  float Schaal;
  int Plot1;
  int Plot2;
  float f;
  float AantalS;
  float eep1;
  float eep2;
  float Min = 2000;
  float Max = 0;
  float Sfactor;
  digitalWrite(TFTL, HIGH);
  for (int x = StartA ; x < StopA; x += 2) {
    eep1 = byte2float (x , ErBij);
    //Serial.print("adres : ");
    //Serial.print(x);
    //Serial.print("  waarde : ");
    //Serial.println(eep1);
    if ( eep1 < Min) {
      Min = eep1;
    }
    if ( eep1 > Max) {
      Max = eep1;
    }
  }

  f = Max - Min;
  if (f > 10) {
    AantalS = (f / 2) + 3;
    Sfactor = 110 / AantalS;
  }
  else if (f < 2) {
    AantalS = 2;
    Sfactor = 110 / AantalS; // 11 is (220/2) / AantalS)
  }
  else
  {
    AantalS = 6;
    Sfactor = 110 / AantalS; // 11 is (220/2) / AantalS)
    // AantalS = helft aantal lijnen y-as
  }

  Schaal = ((Max + Min) / 2) - AantalS;

  tft.fillScreen(BLACK);
  tft.setTextSize(2);


  tft.setTextColor(WHITE, 0);

  tft.setCursor(5, 223);  // Set position (x,y)
  tft.println("-24u");  // Print a text or value

  tft.setCursor(80, 223);  // Set position (x,y)
  tft.println("-18u");  // Print a text or value

  tft.setCursor(155, 223);  // Set position (x,y)
  tft.println("-12u");  // Print a text or value

  tft.setCursor(230, 223); // Set position (x,y)
  tft.println("-6u");

  tft.drawLine(20, 0, 20, 220, WHITE);
  tft.drawLine(10, 220, 320, 220, WHITE);

  for (byte y = 0 ; y < AantalS * 2; y++) {
    tft.drawLine(10, y * Sfactor, 320, y * Sfactor, 0x1100);
  }
  for (byte x = 1 ; x < 4; x++) {
    tft.drawLine((x * 75) + 20, 0, (x * 75) + 20, 220, 0x1100);// uurlijnen
  }
  for (byte y = 0 ; y < (AantalS * 2); y++) {
    tft.drawLine(10, y * Sfactor, 20, y * Sfactor, 0x1100);// y lijnen
  }

  int xas = 1;
  for (int x = StartA ; x < StopA; x += 2) {

    eep1 = byte2float (x, ErBij);
    eep2 = byte2float (x + 2 , ErBij);
    Plot1 = 220 - ((eep1 - Schaal) * Sfactor);
    Plot2 = 220 - ((eep2 - Schaal) * Sfactor);
    // Serial.print("plot1 : ");
    //Serial.print(Plot1);
    //Serial.print("  plot2 : ");
    // Serial.println(Plot2);

    tft.drawLine( 20 + (xas * 3.26), Plot1, 20 + (( xas + 1) * 3.26), Plot2, RED);

    xas++;


  }
  tft.setTextColor(RED, 0);
  tft.setCursor(100, 5);  // Set position (x,y)
  tft.println(text);  // Print a text or value
  int zz = 1;
  if (ID7 == "T") {
    zz = 2;
  }
  if (ID7 == "B" | ID7 == "T") { // "|" = OR functie
    xas = 1;
    for (int x = StartA ; x < StopA; x += 2) {
      eep1 = byte2float (x, ErBij);
      eep2 = byte2float (x + 2 , ErBij);
      Plot1 = 220 - ((eep1 - Schaal) * Sfactor);
      Plot2 = 220 - ((eep2 - Schaal) * Sfactor);
      tft.drawLine(20 + (xas * 3.26), Plot1, 20 + (( xas + 1) * 3.26), Plot2, YELLOW);
      SensorD( eep1, ErBij, zz);
      delay(50);
      tft.drawLine( 20 + (xas * 3.26), Plot1, 20 + (( xas + 1) * 3.26), Plot2, RED);
      xas++;

    }
  }
}
//------------------------------------------------------------------------------------------
void WeerTrend() {
  float Uur3;
  float Uur6;
  float Uur12;
  float Uur24;
  float eep1;
  float eep2;
  digitalWrite(TFTL, HIGH);
  eep1 = byte2float (188, 950);
  eep2 = byte2float (164, 950);
  Uur3 = eep1 - eep2;
  eep2 = byte2float (140, 950);
  Uur6 = eep1 - eep2;
  eep2 = byte2float (92, 950);
  Uur12 = eep1 - eep2;
  eep2 = byte2float (0, 950);
  Uur24 = eep1 - eep2;
  tft.fillScreen(BLACK);
  tft.setTextSize(3);
  tft.setTextColor(GREEN, 0); // rood Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 0);  // Set position (x,y)
  tft.println("--- Luchtdruk ---");

  tft.setCursor(10, 33);  // Set position (x,y)
  tft.println("Max : ");  // Print a text or value
  tft.setCursor(120, 33);  // Set position (x,y)
  eep1 = byte2float (202, 950);
  tft.println(eep1);  // Print a text or value

  tft.setCursor(10, 66);  // Set position (x,y)
  tft.println("Min : ");  // Print a text or value
  tft.setCursor(120, 66);  // Set position (x,y)
  eep2 = byte2float (200, 950);
  tft.println(eep2);  // Print a text or value

  tft.setCursor(10, 99);  // Set position (x,y)
  tft.println("3 uur  : ");  // Print a text or value
  tft.setCursor(200, 99);  // Set position (x,y)
  tft.println(Uur3);  // Print a text or value

  tft.setCursor(10, 133);  // Set position (x,y)
  tft.println("6 uur  : ");  // Print a text or value
  tft.setCursor(200, 133);  // Set position (x,y)
  tft.println(Uur6);  // Print a text or value

  tft.setCursor(10, 166);  // Set position (x,y)
  tft.println("12 uur : ");  // Print a text or value
  tft.setCursor(200, 166);  // Set position (x,y)
  tft.println(Uur12);  // Print a text or value

  tft.setCursor(10, 210);  // Set position (x,y)
  tft.println("24 uur : ");  // Print a text or value
  tft.setCursor(200, 210);  // Set position (x,y)
  tft.println(Uur24);  // Print a text or value

}
//--------------------------------------------------------------
void THData() {
  float eep2;
  digitalWrite(TFTL, HIGH);
  tft.fillScreen(BLACK);
  tft.setTextSize(3);
  tft.setTextColor(RED, 0); // rood Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 0);  // Set position (x,y)
  tft.println("-- Temperatuur --");
  tft.setCursor(10, 33);  // Set position (x,y)
  tft.println("Max : ");  // Print a text or value
  tft.setCursor(120, 33);  // Set position (x,y)
  eep2 = byte2float (1202, 0);
  tft.println(eep2);  // Print a text or value

  tft.setCursor(10, 66);  // Set position (x,y)
  tft.println("Min : ");  // Print a text or value
  tft.setCursor(120, 66);  // Set position (x,y)
  eep2 = byte2float (1200, 0);
  tft.println(eep2);  // Print a text or value

  tft.setTextColor(BLUE, 0); // rood Set color of text. First is the color of text and after is color of background
  tft.setCursor(10, 99);  // Set position (x,y)
  tft.println("---   Hygro   ---");
  tft.setCursor(10, 133);  // Set position (x,y)
  tft.println("Max : ");  // Print a text or value
  tft.setCursor(120, 133);  // Set position (x,y)
  eep2 = byte2float (2202, 0);
  tft.println(eep2);  // Print a text or value

  tft.setCursor(10, 166);  // Set position (x,y)
  tft.println("Min : ");  // Print a text or value
  tft.setCursor(120, 166);  // Set position (x,y)
  eep2 = byte2float (2200, 0);
  tft.println(eep2);  // Print a text or value
}
//--------------------------------------------------------------
void DotMode(byte LB, byte HB) {
  if (LB == 0) {
    HB = HB - 1;
  }
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, rij2[LB]);
  shiftOut(dataPin, clockPin, MSBFIRST, rij1[LB]);
  shiftOut(dataPin, clockPin, MSBFIRST, kolom2BM[HB]);
  shiftOut(dataPin, clockPin, MSBFIRST, kolom1BM[HB]);
  digitalWrite(latchPin, HIGH);

}
//----------------------------------------------------------

void BarCode(int DL, byte LB, byte HB) {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, rij2BM[LB]);
  shiftOut(dataPin, clockPin, MSBFIRST, rij1BM[LB]);
  shiftOut(dataPin, clockPin, MSBFIRST, kolom2BM[HB]);
  shiftOut(dataPin, clockPin, MSBFIRST, kolom1BM[HB]);
  digitalWrite(latchPin, HIGH);
  delayMicroseconds(DL);
}

//-----------------------------------------------------------

void BarMode(byte LB, byte HB) {
  int DL;

  //LB = 6;
  //HB = 7;
  //Serial.println(LDruk);
  //Serial.println(HB);
  //Serial.println(LB);
  switch (HB) {
    case 0:
      DL = 100;
      break;
    case 1:
      DL = 200;
      BarCode(DL, 0, 0);// LB,HB
      break;
    case 2:
      DL = 300;
      BarCode(DL, 0, 0);
      BarCode(DL, 0, 1);
      break;
    case 3:
      DL = 400;
      for (byte x = 0; x <= 2; x++)
      {
        BarCode(DL, 0, x);
      }
      break;
    case 4:
      DL = 500;
      for (byte x = 0; x <= 3; x++)
      {
        BarCode(DL, 0, x);
      }
      break;
    case 5:
      DL = 600;
      for (byte x = 0; x <= 4; x++)
      {
        BarCode(DL, 0, x);
      }
      break;
    case 6:
      DL = 700;
      for (byte x = 0; x <= 5; x++)
      {
        BarCode(DL, 0, x);
      }
      break;
    case 7:
      DL = 800;
      for (byte x = 0; x <= 6; x++)
      {
        BarCode(DL, 0, x);
      }
      break;
    case 8:
      DL = 900;
      for (byte x = 0; x <= 7; x++)
      {
        BarCode(DL, 0, x);
      }
      break;
    case 9:
      DL = 900;
      for (byte x = 0; x <= 8; x++)
      {
        BarCode(DL, 0, x);
      }
      break;
    default:
      BarCode(0, 10, 11);
      digitalWrite(LedRange, LOW);
      break;
  }
  if (LB > 0) {
    BarCode(DL, LB, HB);
  }
}


//-------------------------------------------


void Bartest() {

  tft.setTextColor(0xF9E0, 0);
  tft.setTextSize(5);
  for (byte x = 1; x <= 100; x++) {
    LB = Eenh(x);
    HB = Tiental(x);
    DotMode(LB, HB);
    tft.setCursor(150, 80);
    tft.println(x);
    delay(15);
  }
  //tft.fillScreen(BLACK);
  tft.setTextSize(3);

}

//-----------------------------------------
byte Eenh(byte waarde) {
  byte test = waarde % 10;// % = modulo
  return test;
}
//---------------------------------------------
byte Tiental(byte waarde) {
  byte test2 = waarde / 10;
  return test2;
}
//--------------------------------------------------

Credits

jg53fn55
0 projects • 4 followers
I am retired.
Contact

Comments

Please log in or sign up to comment.