Translate

Tensimeter Digital Interface LCD TFT ILI9341

Tensimeter Digital Interface LCD TFT ILI9341


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tensi yaitu sistol dan diastol dengan lcd TFT ILI9341 dengan mikrokontroller yang dipakai yaitu wemos d1 mini. untuk lebih jelasnya berikut aalah koding dan skemanya.


1. Skema



2. Program Arduino IDE

#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "MAX30100.h"

#define TFT_CS         10
#define TFT_DC         8
//#define TFT_LED      5v
#define TFT_RST        9
#define TFT_MOSI       11
#define TFT_CLK        13
#define TFT_MISO       12

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

MAX30100* pulseOxymeter;

int motor1 = 3;
int motor2 = 4;
int solenoid1 = 5;
int solenoid2 = 6;

float spo;
float bpm;
int counter;
int dataadc;
int tombol = 7;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;

void setup() {
  
  Serial.begin(9600);
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextSize(2);
  tft.setRotation(3); 

  pinMode(motor1,OUTPUT);
  pinMode(motor2,OUTPUT);
  pinMode(solenoid1,OUTPUT);
  pinMode(solenoid2,OUTPUT);
  pinMode(tombol,INPUT_PULLUP);

  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid1,LOW);
  digitalWrite(solenoid2,LOW);

  Wire.begin();
  pulseOxymeter = new MAX30100();
}

void loop() 
{

pulseoxymeter_t result = pulseOxymeter->update();
  
if( result.pulseDetected == true )
  {        
    bpm = result.heartBPM;
    spo = result.SaO2;
  }
  
  tft.setCursor(10, 10);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("Sis/Dia: ");  
  tft.print(sistolex);  
  tft.print(" / "); 
  tft.print(diastolex);  
  tft.print("  "); 

  tft.setCursor(10, 40);
  tft.setTextColor(ILI9341_GREEN,ILI9341_BLACK);  
  tft.print("B/S: ");  
  tft.print(bpm);  
  tft.print(" / "); 
  tft.print(spo);  
  tft.print("  "); 
  
 tombolx = digitalRead(tombol); 

 if(tombolx == LOW){
  mark = 0;
  delay(1000);
  digitalWrite(motor1,HIGH);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid1,HIGH);
  digitalWrite(solenoid2,LOW);
  mulai();
  }

counter++;

if(counter > 100){
 counter = 0;
}

}

void mulai(){
  
dataadc = analogRead(A0);
mmhg = (dataadc - 46.222) / 3.2;

if((mmhg >= mmhgx + 10)&&(mmhg > 100)&&(mark == 0)){
//digitalWrite(motor,LOW); 
//Serial.println("SISTOLE"); 
sistole = mmhg;
mark = 2; 
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);
}

if((mmhg >= mmhgx + 5)&&(mmhg > 50)&&(mmhg < 90)&&(mark == 2)){
//digitalWrite(motor,LOW); 
Serial.println("DIASTOLE"); 
diastole = mmhg;
mark = 3;
}

  tft.setCursor(10, 80);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("S: ");  
  tft.print(mmhg);  
  tft.print("  ");  

if(mmhg >= 150)
{
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);  
}

mmhgx = mmhg;

//Serial.println(mmhg);

if((mark == 3)&&(mmhg < 50)){
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
  digitalWrite(solenoid1,LOW);
  digitalWrite(solenoid2,LOW);
return;  
}

if((mark == 2)&&(mmhg < 50)){
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,90);
  digitalWrite(solenoid1,LOW);
  digitalWrite(solenoid2,LOW);
return;  
}

delay(1);   
mulai();  
}



3. VIDEO HASILNYA


No comments:

Post a Comment