Last active
March 3, 2022 02:35
-
-
Save Aabill/9de30cbee94bd7db70aefb51fa41a1d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <avr/wdt.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_GrayOLED.h> | |
#include <Adafruit_SPITFT.h> | |
#include <Adafruit_SPITFT_Macros.h> | |
#include <gfxfont.h> | |
//#if 1 | |
#include <Adafruit_GFX.h> | |
#include <MCUFRIEND_kbv.h> | |
MCUFRIEND_kbv tft; | |
#include <TouchScreen.h> | |
#define MINPRESSURE 300 | |
#define MAXPRESSURE 1000 | |
// PULSERATE & OXYGENLEVEL | |
#include <Wire.h> | |
#include <heartRate.h> | |
//#include <MAX30105.h> | |
//#include <spo2_algorithm.h> | |
#include "MAX30105.h" | |
#include "spo2_algorithm.h" | |
#include <Adafruit_MLX90614.h> | |
//#include "MAX30105.h" | |
MAX30105 particleSensor; | |
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); | |
const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good. | |
byte rates[RATE_SIZE]; //Array of heart rates | |
byte rateSpot = 0; | |
long lastBeat = 0; //Time at which the last beat occurred | |
float beatsPerMinute; | |
int beatAvg; | |
char sbuffer[30], ch; | |
unsigned char pos; | |
unsigned char read1, read2, read3; | |
//OL | |
#define MAX_BRIGHTNESS 255 | |
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) | |
//Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format | |
//To solve this problem, 16-bit MSB of the sampled data will be truncated. Samples become 16-bit data. | |
uint16_t irBuffer[100]; //infrared LED sensor data | |
uint16_t redBuffer[100]; //red LED sensor data | |
#else | |
uint32_t irBuffer[100]; //infrared LED sensor data | |
uint32_t redBuffer[100]; //red LED sensor data | |
#endif | |
int32_t bufferLength; //data length | |
int32_t spo2; //SPO2 value | |
int8_t validSPO2; //indicator to show if the SPO2 calculation is valid | |
int32_t heartRate; //heart rate value | |
int8_t validHeartRate; //indicator to show if the heart rate calculation is valid | |
byte pulseLED = 11; //Must be on PWM pin | |
byte readLED = 13; //Blinks with each data read | |
//end OL | |
// END PULSERATE & OXYGEN LEVEL | |
// ALL Touch panels and wiring is DIFFERENT | |
// copy-paste results from TouchScreen_Calibr_native.ino | |
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341 | |
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139; | |
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); | |
Adafruit_GFX_Button A_btn, B_btn, C_btn, D_btn, E_btn, F_btn, G_btn, H_btn, I_btn, J_btn, K_btn, L_btn, M_btn, N_btn, O_btn, P_btn, Q_btn, R_btn, S_btn, T_btn, U_btn, V_btn, W_btn, X_btn, Y_btn, Z_btn, DEL_btn, SPACE_btn, ENTER_btn, CLEAR_btn, one_btn, | |
two_btn, three_btn, four_btn, five_btn, six_btn, seven_btn, eight_btn, nine_btn, zero_btn, male_btn, female_btn, reset_btn, next_btn;//on_btn, off_btn,; | |
Adafruit_GFX_Button *keyButtons[] = { &Q_btn, &W_btn, &E_btn, &R_btn, &T_btn, &Y_btn, &U_btn, &I_btn, &O_btn, &P_btn, &A_btn, &S_btn, &D_btn, &F_btn, &G_btn, &H_btn, &J_btn, &K_btn, &L_btn, &Z_btn, &X_btn, &C_btn, &V_btn, &B_btn, &N_btn, &M_btn }; | |
Adafruit_GFX_Button *numButtons[] = { &one_btn, &two_btn, &three_btn, &four_btn, &five_btn, &six_btn, &seven_btn, &eight_btn, &nine_btn, &zero_btn}; | |
const char* line1[] = {"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"}; | |
const char* line2[] = {"A", "S", "D", "F", "G", "H", "J", "K", "L"}; | |
const char* line3[] = {"Z", "X", "C", "V", "B", "N", "M"}; | |
const char* ageLine[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}; | |
int pixel_x, pixel_y; //Touch_getXY() updates global vars | |
// BP Variables | |
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(50, 51); // RX, TX | |
// Mass Weight & HEIGHT Variables | |
#include <HX711_ADC.h> | |
#if defined(ESP8266)|| defined(ESP32) || defined(AVR) | |
#include <EEPROM.h> | |
#endif | |
//pins: | |
const int HX711_dout = 37; //mcu > HX711 dout pin | |
const int HX711_sck = 36; //mcu > HX711 sck pin | |
//HX711 constructor: | |
HX711_ADC LoadCell(HX711_dout, HX711_sck); | |
const int calVal_calVal_eepromAdress = 0; | |
unsigned long Masst = 0; | |
// Height | |
#define echoPin 31 // attach pin D2 Arduino to pin Echo of HC-SR04 | |
#define trigPin 30 //attach pin D3 Arduino to pin Trig of HC-SR04 | |
// defines variables | |
long duration; // variable for the duration of sound wave travel | |
float distance; // variable for the distance measurement | |
// Printer Settings | |
#include "Adafruit_Thermal.h" | |
//#include "adalogo.h" | |
//#include "adaqrcode.h" | |
// Here's the new syntax when using SoftwareSerial (e.g. Arduino Uno) ---- | |
// If using hardware serial instead, comment out or remove these lines: | |
#include "SoftwareSerial.h" | |
#define TX_PIN 53 // Arduino transmit YELLOW WIRE labeled RX on printer | |
#define RX_PIN 52 // Arduino receive GREEN WIRE labeled TX on printer | |
SoftwareSerial printerSerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first | |
Adafruit_Thermal printer(&printerSerial); // Pass addr to printer constructor | |
//void(* resetFunc) (void) = 0; // declare reset fuction at address 0 | |
void softwareReset( uint8_t prescaller) { | |
// start watchdog with the provided prescaller | |
wdt_enable( prescaller); | |
// wait for the prescaller time to expire | |
// without sending the reset signal by using | |
// the wdt_reset() method | |
while(1) {} | |
} | |
bool Touch_getXY(void) | |
{ | |
TSPoint p = ts.getPoint(); | |
pinMode(YP, OUTPUT); //restore shared pins | |
pinMode(XM, OUTPUT); | |
digitalWrite(YP, HIGH); //because TFT control pins | |
digitalWrite(XM, HIGH); | |
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE); | |
if (pressed) { | |
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me | |
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height()); | |
} | |
return pressed; | |
} | |
#define BLACK 0x0000 | |
#define BLUE 0x001F | |
#define RED 0xF800 | |
#define GREEN 0x07E0 | |
#define CYAN 0x07FF | |
#define MAGENTA 0xF81F | |
#define YELLOW 0xFFE0 | |
#define WHITE 0xFFFF | |
// Variables Global | |
struct PRINT { | |
String Name; | |
String Age; | |
String Gender; | |
String BP; | |
String PulseRate; | |
String PulseRateAVG; | |
String PulseRateBPM; | |
String OxygenLevel; | |
String Height; | |
String Weight; | |
String BodyTemperature; | |
String BodyStatus; | |
float metricHeight; | |
float massWeight; | |
String BMI; | |
String Print; | |
float BMIvalue; | |
int NextSetup; | |
}; | |
PRINT person = {}; | |
String patientStatus = ""; | |
String textInput = ""; | |
String ageInput = ""; | |
// String Name = ""; | |
// | |
// String Age = ""; | |
// String Gender = ""; | |
// String PulseRateAVG = ""; | |
// String PulseRateBPM = ""; | |
// String SPO2 = ""; | |
void inputValue(String val) { | |
tft.fillRect(10, 50, 300, 60, BLACK); | |
tft.setTextSize(2); | |
tft.setCursor(12, 55); | |
tft.print(val); | |
} | |
void inputQuestion(String text, bool showInput = true, String showValue = "", int yPointer = 15, String ThirdLine="") { | |
tft.fillRect(10, yPointer - 5, 300, 30, BLUE); | |
tft.setCursor(10, yPointer); | |
tft.setTextSize(2); | |
tft.setTextColor(WHITE); | |
tft.print(" " + text); | |
if (showInput) { | |
tft.fillRect(10, 50, 300, 60, BLACK); | |
tft.setCursor(15, 55); | |
tft.print(showValue); | |
tft.setCursor(15, 85); | |
tft.print(ThirdLine); | |
} | |
} | |
void nameSetup(void) { | |
tft.fillScreen(WHITE); | |
inputQuestion("Enter your name."); | |
int buttonPlacefromLeft = 0; | |
for ( int i = 0; i < 10; i++) { | |
int buttonSpace = 30; | |
if (i == 0) { | |
buttonSpace = 25; | |
} | |
buttonPlacefromLeft = buttonPlacefromLeft + buttonSpace; | |
keyButtons[i]->initButton(&tft, buttonPlacefromLeft, 140, 30, 40, WHITE, CYAN, BLACK, line1[i], 2); | |
keyButtons[i]->drawButton(false); | |
} | |
buttonPlacefromLeft = 10; | |
for ( int i = 10; i > 9 && i < 19; i++) { | |
int buttonSpace = 30; | |
buttonPlacefromLeft = buttonPlacefromLeft + buttonSpace; | |
keyButtons[i]->initButton(&tft, buttonPlacefromLeft, 180, 30, 40, WHITE, CYAN, BLACK, line2[i - 10], 2); | |
keyButtons[i]->drawButton(false); | |
} | |
buttonPlacefromLeft = 40; | |
for ( int i = 19; i > 18 && i < 26; i++) { | |
int buttonSpace = 30; | |
buttonPlacefromLeft = buttonPlacefromLeft + buttonSpace; | |
keyButtons[i]->initButton(&tft, buttonPlacefromLeft, 220, 30, 40, WHITE, CYAN, BLACK, line3[i - 19], 2); | |
keyButtons[i]->drawButton(false); | |
} | |
// Initialize Del Button | |
DEL_btn.initButton(&tft, 50, 270, 60, 40, WHITE, RED, WHITE, "DEL", 2); | |
DEL_btn.drawButton(false); | |
// Initialize Clear Button | |
CLEAR_btn.initButton(&tft, 50, 320, 70, 40, WHITE, RED, WHITE, "CLEAR", 2); | |
CLEAR_btn.drawButton(false); | |
// Intialize Space Button | |
SPACE_btn.initButton(&tft, 160, 260, 90, 40, WHITE, CYAN, BLACK, "SPACE", 2); | |
SPACE_btn.drawButton(false); | |
// Initialize Enter Button | |
ENTER_btn.initButton(&tft, 260, 320, 80, 40, WHITE, BLUE, WHITE, "ENTER", 2); | |
ENTER_btn.drawButton(false); | |
} | |
void ageSetup(void) { | |
tft.fillScreen(WHITE); | |
const String firstName = getSplitValue(person.Name, ' ', 0); | |
inputQuestion(firstName + "'S AGE IS:"); | |
int buttonPlacefromLeft = 0; | |
int buttonSpace = 50; | |
int topPad = 140; | |
for ( int i = 0; i < 10; i++) { | |
if ( i == 3 || i == 6 ) { | |
topPad = topPad + 50; | |
buttonPlacefromLeft = 0; | |
} | |
buttonPlacefromLeft = buttonPlacefromLeft + buttonSpace; | |
if ( i == 9 ) { | |
topPad = 290; | |
buttonPlacefromLeft = 100; | |
} | |
numButtons[i]->initButton(&tft, buttonPlacefromLeft, topPad, 50, 50, WHITE, CYAN, BLACK, ageLine[i], 2); | |
numButtons[i]->drawButton(false); | |
} | |
// Initialize Del Button | |
DEL_btn.initButton(&tft, 220, 140, 60, 40, WHITE, RED, WHITE, "DEL", 2); | |
DEL_btn.drawButton(false); | |
// Initialize Enter Button | |
ENTER_btn.initButton(&tft, 220, 290, 80, 40, WHITE, BLUE, WHITE, "ENTER", 2); | |
ENTER_btn.drawButton(false); | |
} | |
void choiceSetup(String question, int yPointer = 0) { | |
if (yPointer > 0) { | |
inputQuestion(question, false, "", yPointer); | |
} else { | |
inputQuestion(question, false); | |
} | |
if (patientStatus == "getGender") { | |
one_btn.initButton(&tft, 110, 100, 100, 100, WHITE, CYAN, BLACK, "MALE", 2); | |
one_btn.drawButton(false); | |
zero_btn.initButton(&tft, 210, 100, 100, 100, WHITE, CYAN, BLACK, "FEMALE", 2); | |
zero_btn.drawButton(false); | |
} | |
if (patientStatus == "getPrint") { | |
one_btn.initButton(&tft, 110, yPointer + 95, 100, 100, WHITE, CYAN, BLACK, "NO", 2); | |
one_btn.drawButton(false); | |
zero_btn.initButton(&tft, 210, yPointer + 95, 100, 100, WHITE, CYAN, BLACK, "YES", 2); | |
zero_btn.drawButton(false); | |
} | |
} | |
void midButtonSetup(char* text) { | |
reset_btn.initButton(&tft, 160, 200, 120, 80, WHITE, CYAN, BLACK, text, 2); | |
reset_btn.drawButton(false); | |
} | |
void BPSETUP(void) { | |
Serial1.begin(9600); | |
tft.fillScreen(WHITE); | |
const String firstName = getSplitValue(person.Name, ' ', 0); | |
inputQuestion("GETTING " + firstName + "'S BP", true, "Please Start BP & wait."); | |
mySerial.begin(4800); | |
delay(100); | |
} | |
void WEIGHTSETUP(void) { | |
// Start Weight Setup | |
delay(10); | |
Serial.println("Starting..."); | |
float calibrationValue; // calibration value | |
calibrationValue = 14481.25;//696.0 - 21.33; // uncomment this if you want to set this value in the sketch | |
#if defined(ESP8266) || defined(ESP32) | |
//EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch this value from eeprom | |
#endif | |
//EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch this value from eeprom | |
LoadCell.begin(); | |
//LoadCell.setReverseOutput(); | |
unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time | |
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step | |
LoadCell.start(stabilizingtime, _tare); | |
if (LoadCell.getTareTimeoutFlag()) { | |
Serial.println("Timeout, check MCU>HX711 wiring and pin designations"); | |
} | |
else { | |
LoadCell.setCalFactor(calibrationValue); // set calibration factor (float) | |
Serial.println("Startup is complete"); | |
} | |
// while (!LoadCell.update()); | |
// Serial.print("Calibration value: "); | |
// Serial.println(LoadCell.getCalFactor()); | |
// Serial.print("HX711 measured conversion time ms: "); | |
// Serial.println(LoadCell.getConversionTime()); | |
// Serial.print("HX711 measured sampling rate HZ: "); | |
// Serial.println(LoadCell.getSPS()); | |
// Serial.print("HX711 measured settlingtime ms: "); | |
// Serial.println(LoadCell.getSettlingTime()); | |
// Serial.println("Note that the settling time may increase significantly if you use delay() in your sketch!"); | |
// if (LoadCell.getSPS() < 7) { | |
// Serial.println("!!Sampling rate is lower than specification, check MCU>HX711 wiring and pin designations"); | |
// } | |
// else if (LoadCell.getSPS() > 100) { | |
// Serial.println("!!Sampling rate is higher than specification, check MCU>HX711 wiring and pin designations"); | |
// } | |
} | |
void HEIGHTSETUP() { | |
// Start Height Setup | |
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT | |
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT | |
// Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed | |
Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor | |
Serial.println("with Arduino UNO R3"); | |
} | |
bool hasName, hasAge, hasGender, hasBP, hasPulseRate, hasOxygenLevel, hasHeight, hasWeight, hasTemp, hasPrint = false; | |
void setup(void) | |
{ | |
Serial.begin(115200); | |
uint16_t ID = tft.readID(); | |
Serial.print("TFT ID = 0x"); | |
Serial.println(ID, HEX); | |
Serial.println("Calibrate for your Touch Panel"); | |
if (ID == 0xD3D3) ID = 0x9486; // write-only shield | |
tft.begin(ID); | |
tft.setRotation(0); //PORTRAIT | |
// pulseRateOxygenSETUP(); | |
// WEIGHTSETUP(); | |
Serial.println("Setup() finished"); | |
pinMode(33,OUTPUT); | |
buzz(); | |
tft.fillScreen(WHITE); | |
inputQuestion("Hi! I'm iSign", true, "Welcome and enjoy", 15, "your time with me."); | |
delay(3000); | |
} | |
void buzz() { | |
digitalWrite(33,HIGH); | |
delay(175); // ...for 1 sec | |
digitalWrite(33,LOW); | |
} | |
/* two buttons are quite simple | |
*/ | |
void pulseRateOxygenSETUP() | |
{ | |
Serial.println("Initializing pulseRateSensor..."); | |
mlx.begin(); | |
// Initialize sensor | |
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed | |
{ | |
Serial.println("MAX30105 was not found. Please check wiring/power. "); | |
while (1); | |
} | |
Serial.println("Place your index finger on the sensor with steady pressure."); | |
particleSensor.setup(); //Configure sensor with default settings | |
particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running | |
particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED | |
} | |
void OLSETUP() { | |
pinMode(pulseLED, OUTPUT); | |
pinMode(readLED, OUTPUT); | |
// mlx.begin(); | |
// Initialize sensor | |
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed | |
{ | |
Serial.println(F("MAX30105 was not found. Please check wirwing/power.")); | |
while (1); | |
} | |
// Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion")); | |
// while (Serial.available() == 0) ; //wait until user presses a key | |
// Serial.read(); | |
byte ledBrightness = 60; //Options: 0=Off to 255=50mA | |
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32 | |
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green | |
byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200 | |
int pulseWidth = 411; //Options: 69, 118, 215, 411 | |
int adcRange = 4096; //Options: 2048, 4096, 8192, 16384 | |
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings | |
} | |
void resetting(int caseSetup=0) { | |
bool down = Touch_getXY(); | |
reset_btn.press(down && reset_btn.contains(pixel_x, pixel_y)); | |
if (reset_btn.justReleased()) reset_btn.drawButton(); | |
if (reset_btn.justPressed()) { | |
reset_btn.drawButton(true); | |
if (patientStatus == "printingResult") { | |
softwareReset( WDTO_60MS); | |
} | |
else { | |
setNextSetup(caseSetup); | |
} | |
} | |
} | |
int nextSetup = 1; | |
bool readOL = true; | |
void loop(void) | |
{ | |
if (patientStatus == "getName") { | |
inputName(); | |
Serial.println("Getting Name"); | |
if (hasName) { | |
// gettingAge = true; | |
setNextSetup(2); | |
} | |
} | |
if (patientStatus == "getAge") { | |
inputAge(); | |
Serial.println("Getting Age"); | |
if (hasAge) { | |
// gettingGender = true; | |
setNextSetup(3); | |
} | |
} | |
if (patientStatus == "getGender") { | |
choosing("MALE", "FEMALE"); | |
Serial.println("Choosing Gender"); | |
if (hasGender) { | |
// gettingBP = true; | |
setNextSetup(4); | |
patientStatus = ""; | |
} | |
} | |
if (patientStatus == "getBP") { | |
Serial.println("Getting BP"); | |
loopBP(); | |
if (hasBP) { | |
buzz(); | |
// gettingOL = true; | |
tft.fillScreen(WHITE); | |
inputQuestion("Next is Pulse/SPO2", true, "Before tapping proceed,", 15, "place finger first."); | |
midButtonSetup("PROCEED"); | |
Serial.println("Wait for Next Setup"); | |
patientStatus = "getNextSetup"; | |
person.NextSetup = 5; | |
} | |
} | |
if (patientStatus == "getOL") { | |
if (hasOxygenLevel) { | |
buzz(); | |
tft.fillScreen(WHITE); | |
inputQuestion("Next is Temperature", true, "Put wrist close to the", 15, "little circle sensor."); | |
midButtonSetup("PROCEED"); | |
Serial.println("Wait for Next Setup"); | |
patientStatus = "getNextSetup"; | |
person.NextSetup = 6; | |
}else { | |
loopOL(); | |
} | |
} | |
if (patientStatus == "getHeight") { | |
loopHeight(); | |
if (hasHeight) { | |
buzz(); | |
// gettingWeight = true; | |
tft.fillScreen(WHITE); | |
inputQuestion("All done!", true, "Proceed to show result.", 15, "Thank you."); | |
midButtonSetup("PROCEED"); | |
Serial.println("Wait for Next Setup"); | |
patientStatus = "getNextSetup"; | |
person.NextSetup = 9; | |
} | |
} | |
if (patientStatus == "getWeight") { | |
// loopWeight(); | |
float weight; | |
float weights[10]; | |
int totWeights[10] = {0,0,0,0,0,0,0,0,0,0}; | |
weight = loopWeight(); | |
Serial.println(round(weight)); | |
delay(50); | |
if (weight > 10) { | |
Serial.println("pasok"); | |
for (int m = 0; m < 10; m++) { | |
// store to weights array; | |
weights[m] = loopWeight(); | |
Serial.println(weights[m]); | |
delay(100); | |
} | |
for (int i = 0; i < 10; i++) { | |
for (int j = 0; j < 10; j++) { | |
if ( round(weights[i]) == round(weights[j]) ) { | |
totWeights[i]++; | |
} | |
} | |
Serial.println("tot Weight" + String(totWeights[i])); | |
if (totWeights[i] == 10) { | |
Serial.println("Got The Best Value!"); | |
float sumWeight = 0.00; | |
for (int k = 0; k < 10; k++) { | |
sumWeight += weights[k]; | |
Serial.print(String(weights[k]) + ", "); | |
} | |
Serial.println(); | |
weight = sumWeight / 10; | |
Serial.println("Weight is = "+String(weight) + " kg"); | |
String massKG = ""; | |
massKG.concat(weight); | |
massKG.concat(" kg"); | |
person.Weight = massKG; | |
if (person.Weight.length() > 0) { | |
person.massWeight = weight; | |
} | |
buzz(); | |
delay(1000); | |
tft.fillScreen(WHITE); | |
inputQuestion("Next is Height", true, "Make sure the sensor,", 15, "above sees your head."); | |
midButtonSetup("PROCEED"); | |
Serial.println("Wait for Next Setup"); | |
patientStatus = "getNextSetup"; | |
person.NextSetup = 8; | |
goto bailout; | |
} | |
} | |
bailout: | |
for( int i = 0; i < 10; i++) { | |
Serial.print(String(totWeights[i]) + ","); | |
} | |
Serial.println(); | |
for( int i = 0; i < 10; i++) { | |
Serial.print(String(weights[i]) + ","); | |
} | |
Serial.println(); | |
} | |
} | |
if (patientStatus == "getTemp") { | |
loopTemp(); | |
if (hasTemp) { | |
buzz(); | |
tft.fillScreen(WHITE); | |
inputQuestion("Next is Weight", true, "After tapping proceed,", 15, "enter the platform."); | |
midButtonSetup("PROCEED"); | |
Serial.println("Wait for Next Setup"); | |
patientStatus = "getNextSetup"; | |
person.NextSetup = 7; | |
} | |
} | |
if (patientStatus == "getPrint") { | |
choosing("NO", "YES"); | |
if (hasPrint) { | |
Serial.print("Print Selected: "); | |
Serial.println(person.Print); | |
// printNow = true; | |
// setNextSetup(10); | |
nextSetup = 10; | |
patientStatus = ""; | |
buzz(); | |
goto printNowBailOut; | |
} | |
} | |
if (patientStatus == "getNextSetup") { | |
resetting(person.NextSetup); | |
} | |
if (patientStatus == "printingResult") { | |
resetting(); | |
} | |
// Serial.println( "Setup ------>" + String(nextSetup) ); | |
// nextSetup is initially set to 1 --> Start Here | |
switch (nextSetup) { | |
case 1: | |
Serial.println("inputName"); | |
patientStatus = "getName"; | |
nameSetup(); | |
nextSetup = 0; | |
buzz(); | |
break; | |
case 2: | |
Serial.println("inputAge"); | |
patientStatus = "getAge"; | |
ageSetup(); | |
nextSetup = 0; | |
buzz(); | |
break; | |
case 3: | |
Serial.println("Choose Gender"); | |
patientStatus = "getGender"; | |
tft.fillScreen(WHITE); | |
choiceSetup( getSplitValue(person.Name, ' ', 0) + "'S GENDER IS:" ); | |
nextSetup = 0; | |
buzz(); | |
break; | |
case 4: | |
Serial.println("Start BP"); | |
patientStatus = "getBP"; | |
BPSETUP(); | |
nextSetup = 0; | |
break; | |
case 5: | |
Serial.println("Start Oxygen Level"); | |
patientStatus = "getOL"; | |
OLSETUP(); | |
tft.fillScreen(WHITE); | |
inputQuestion("Getting Oxygen Level...", true, "Don't move your finger."); | |
nextSetup = 0; | |
break; | |
case 6: | |
Serial.println("Start Temperature"); | |
patientStatus = "getTemp"; | |
mlx.begin(); | |
tft.fillScreen(WHITE); | |
inputQuestion("Getting Temperature", false); | |
nextSetup = 0; | |
break; | |
case 7: | |
Serial.println("Start Weight"); | |
patientStatus = "getWeight"; | |
WEIGHTSETUP(); | |
// gettingWeight = false; | |
tft.fillScreen(WHITE); | |
inputQuestion("Getting Weight...", true, "Try to be still"); | |
nextSetup = 0; | |
break; | |
case 8: | |
Serial.println("Start Height"); | |
patientStatus = "getHeight"; | |
HEIGHTSETUP(); | |
tft.fillScreen(WHITE); | |
inputQuestion("Getting Height...", true, "Try not to move."); | |
nextSetup = 0; | |
break; | |
case 9: | |
// Calculate BMI | |
// Compute BMI since we have Height and Weight from &person (object); | |
// float BMI = person.massWeight / (person.metricHeight * person.metricHeight); | |
person.BMIvalue = person.massWeight / (person.metricHeight * person.metricHeight);//BMI; | |
if (person.BMIvalue <= 18.5) { | |
person.BMI = "Underweight"; | |
} | |
else if (person.BMIvalue >= 18.51 && person.BMIvalue <= 24.9) { | |
person.BMI = "Normal"; | |
} | |
else if (person.BMIvalue >= 25 && person.BMIvalue <= 29.9) { | |
person.BMI = "Overweight"; | |
} | |
else { | |
person.BMI = "Obese"; | |
} | |
Serial.println("Display Result & Choose Print"); | |
patientStatus = "getPrint"; | |
Serial.println(person.Name); | |
Serial.println(person.Age); | |
Serial.println(person.Gender); | |
Serial.println(person.BP); | |
Serial.println(person.PulseRate); | |
Serial.println(person.OxygenLevel); | |
Serial.println(person.Height); | |
Serial.println(person.Weight); | |
Serial.println(person.BodyTemperature); | |
Serial.println(person.BMI); | |
// TFT LCD Print BMI | |
inputQuestion("BMI", true, person.BMI); | |
delay(3000); | |
tft.fillScreen(WHITE); | |
tft.setCursor(10, 15); | |
tft.setTextSize(1); | |
tft.setTextColor(BLACK); | |
tft.print("Name: " + person.Name); | |
tft.setCursor(10, 35); | |
tft.print("Age: " + person.Age); | |
tft.setCursor(10, 55); | |
tft.print("Gender: " + person.Gender); | |
tft.setCursor(10, 75); | |
tft.print("BP: " + person.BP); | |
tft.setCursor(10, 95); | |
tft.print("Pulse rate: " + person.PulseRate); | |
tft.setCursor(10, 115); | |
tft.print("Oxygen level: " + person.OxygenLevel); | |
tft.setCursor(10, 135); | |
tft.print("Height: " + person.Height); | |
tft.setCursor(10, 155); | |
tft.print("Weight: " + person.Weight); | |
tft.setCursor(10, 175); | |
tft.print("Body temperature: " + person.BodyTemperature + " C"); | |
tft.setCursor(10, 195); | |
tft.print("BMI: " + person.BMI); | |
tft.setCursor(10, 215); | |
tft.print("BMI formula: weight(kg) / height(m) * height(m)"); | |
String metricHeight = "Height in (m) "; | |
metricHeight.concat(person.metricHeight); | |
metricHeight.concat(" meters"); | |
tft.setCursor(10, 235); | |
tft.print(metricHeight); | |
String BMIformula = "BMI = "; | |
BMIformula.concat(person.massWeight); | |
BMIformula.concat("kg / ( "); | |
BMIformula.concat(person.metricHeight); | |
BMIformula.concat("m * "); | |
BMIformula.concat(person.metricHeight); | |
BMIformula.concat("m ) = "); | |
BMIformula.concat(person.BMIvalue); | |
tft.setCursor(10, 255); | |
tft.print(BMIformula);//person.massWeight / (person.metricHeight * person.metricHeight) | |
choiceSetup( "Print Result?", 300); | |
nextSetup = 0; | |
break; | |
default: | |
break; | |
} | |
printNowBailOut: | |
if ( nextSetup == 10) { | |
Serial.println("Print NOW!!!"); | |
patientStatus = "printingResult"; | |
if (person.Print == "YES") { | |
Serial.println("Print NOW!!!"); | |
tft.fillScreen(WHITE); | |
inputQuestion("Printing result...", true, "Please wait."); | |
printerSerial.begin(9600); // Initialize SoftwareSerial (Printer) | |
printer.begin(); // Init printer (same regardless of serial type) | |
printer.wake(); | |
printer.println("NAME : "); | |
printer.println(person.Name); | |
printer.println("AGE : "); | |
printer.print(person.Age); | |
printer.println("GENDER : "); | |
printer.print(person.Gender); | |
printer.println("BLOOD PRESSURE : "); | |
printer.print(person.BP); | |
printer.println("PULSE RATE : "); | |
printer.print(person.PulseRate); | |
printer.println("OXYGEN LEVEL : "); | |
printer.print(person.OxygenLevel); | |
printer.println("HEIGHT : "); | |
printer.print(person.Height); | |
printer.println("WEIGHT : "); | |
printer.print(person.Weight); | |
printer.println("BODY TEMPERATURE : "); | |
printer.print(person.BodyTemperature + " C"); | |
printer.println("BMI : "); | |
printer.print(person.BMI); | |
printer.feed(3); | |
printer.println("NAME : "); | |
printer.println(person.Name); | |
printer.println("AGE : "); | |
printer.print(person.Age); | |
printer.println("GENDER : "); | |
printer.print(person.Gender); | |
printer.println("BLOOD PRESSURE : "); | |
printer.print(person.BP); | |
printer.println("PULSE RATE : "); | |
printer.print(person.PulseRate); | |
printer.println("OXYGEN LEVEL : "); | |
printer.print(person.OxygenLevel); | |
printer.println("HEIGHT : "); | |
printer.print(person.Height); | |
printer.println("WEIGHT : "); | |
printer.print(person.Weight); | |
printer.println("BODY TEMPERATURE : "); | |
printer.print(person.BodyTemperature + " C"); | |
printer.println("BMI : "); | |
printer.print(person.BMI); | |
printer.feed(3); | |
printer.sleep(); | |
Serial.println("Exit."); | |
tft.fillScreen(WHITE); | |
inputQuestion("Done. Thankyou!", false); | |
delay(3000); | |
tft.fillScreen(WHITE); | |
midButtonSetup("RESET"); | |
} | |
if (person.Print == "NO") { | |
Serial.println("Exit."); | |
tft.fillScreen(WHITE); | |
inputQuestion("Done. Thankyou!", true, "You can go now."); | |
delay(3000); | |
tft.fillScreen(WHITE); | |
midButtonSetup("RESET"); | |
} | |
nextSetup = 0; | |
} | |
} | |
void inputName(void) { | |
bool down = Touch_getXY(); | |
// Q_btn.press(down && Q_btn.contains(pixel_x, pixel_y)); | |
// if (Q_btn.justReleased()) Q_btn.drawButton(); | |
// if (Q_btn.justPressed()) { | |
// Q_btn.drawButton(true); | |
// textInput += "Q"; | |
// inputValue(textInput); | |
// } | |
for (int i = 0; i < 10; i++) { | |
keyButtons[i]->press(down && keyButtons[i]->contains(pixel_x, pixel_y)); | |
if (keyButtons[i]->justReleased()) keyButtons[i]->drawButton(); | |
if (keyButtons[i]->justPressed()) { | |
keyButtons[i]->drawButton(true); | |
textInput += line1[i]; | |
inputValue(textInput); | |
} | |
} | |
for (int i = 10; i < 19; i++) { | |
keyButtons[i]->press(down && keyButtons[i]->contains(pixel_x, pixel_y)); | |
if (keyButtons[i]->justReleased()) keyButtons[i]->drawButton(); | |
if (keyButtons[i]->justPressed()) { | |
keyButtons[i]->drawButton(true); | |
textInput += line2[i - 10]; | |
inputValue(textInput); | |
} | |
} | |
for ( int i = 19; i > 18 && i < 26; i++) { | |
keyButtons[i]->press(down && keyButtons[i]->contains(pixel_x, pixel_y)); | |
if (keyButtons[i]->justReleased()) keyButtons[i]->drawButton(); | |
if (keyButtons[i]->justPressed()) { | |
keyButtons[i]->drawButton(true); | |
textInput += line3[i - 19]; | |
inputValue(textInput); | |
} | |
} | |
SPACE_btn.press(down && SPACE_btn.contains(pixel_x, pixel_y)); | |
if (SPACE_btn.justReleased()) SPACE_btn.drawButton(); | |
if (SPACE_btn.justPressed()) { | |
SPACE_btn.drawButton(true); | |
textInput += " "; | |
inputValue(textInput); | |
} | |
DEL_btn.press(down && DEL_btn.contains(pixel_x, pixel_y)); | |
if (DEL_btn.justReleased()) DEL_btn.drawButton(); | |
if (DEL_btn.justPressed()) { | |
DEL_btn.drawButton(true); | |
textInput.remove(textInput.length() - 1, 1); | |
tft.setTextColor(CYAN); | |
inputValue(textInput); | |
} | |
CLEAR_btn.press(down && CLEAR_btn.contains(pixel_x, pixel_y)); | |
if (CLEAR_btn.justReleased()) CLEAR_btn.drawButton(); | |
if (CLEAR_btn.justPressed()) { | |
CLEAR_btn.drawButton(true); | |
textInput = ""; | |
inputValue(textInput); | |
} | |
ENTER_btn.press(down && ENTER_btn.contains(pixel_x, pixel_y)); | |
if (ENTER_btn.justReleased()) ENTER_btn.drawButton(); | |
if (ENTER_btn.justPressed()) { | |
ENTER_btn.drawButton(true); | |
person.Name = textInput; | |
textInput = ""; | |
hasName = true; | |
} | |
} | |
void inputAge(void) { | |
bool down = Touch_getXY(); | |
for (int i = 0; i < 10; i++) { | |
numButtons[i]->press(down && numButtons[i]->contains(pixel_x, pixel_y)); | |
if (numButtons[i]->justReleased()) numButtons[i]->drawButton(); | |
if (numButtons[i]->justPressed()) { | |
numButtons[i]->drawButton(true); | |
ageInput += ageLine[i]; | |
inputValue(ageInput); | |
} | |
} | |
DEL_btn.press(down && DEL_btn.contains(pixel_x, pixel_y)); | |
if (DEL_btn.justReleased()) DEL_btn.drawButton(); | |
if (DEL_btn.justPressed()) { | |
DEL_btn.drawButton(true); | |
ageInput.remove(ageInput.length() - 1, 1); | |
tft.setTextColor(CYAN); | |
inputValue(ageInput); | |
} | |
ENTER_btn.press(down && ENTER_btn.contains(pixel_x, pixel_y)); | |
if (ENTER_btn.justReleased()) ENTER_btn.drawButton(); | |
if (ENTER_btn.justPressed()) { | |
ENTER_btn.drawButton(true); | |
person.Age = ageInput; | |
ageInput = ""; | |
hasAge = true; | |
} | |
} | |
void nextStep(String title, String instruction, String nextStep) { | |
bool down = Touch_getXY(); | |
} | |
void choosing(String firstChoice, String secondChoice) { | |
bool down = Touch_getXY(); | |
one_btn.press(down && one_btn.contains(pixel_x, pixel_y)); | |
if (one_btn.justReleased()) one_btn.drawButton(); | |
if (one_btn.justPressed()) { | |
one_btn.drawButton(true); | |
if (patientStatus == "getGender") | |
{ | |
person.Gender = firstChoice; | |
hasGender = true; | |
Serial.println("Selected " + firstChoice); | |
} | |
if (patientStatus == "getPrint") | |
{ | |
person.Print = firstChoice; | |
hasPrint = true; | |
} | |
} | |
zero_btn.press(down && zero_btn.contains(pixel_x, pixel_y)); | |
if (zero_btn.justReleased()) zero_btn.drawButton(); | |
if (zero_btn.justPressed()) { | |
zero_btn.drawButton(true); | |
if (patientStatus == "getGender") | |
{ | |
person.Gender = secondChoice; | |
hasGender = true; | |
Serial.println("Selected " + secondChoice); | |
} | |
if (patientStatus == "getPrint") | |
{ | |
person.Print = secondChoice; | |
hasPrint = true; | |
} | |
} | |
} | |
void setNextSetup(int caseSetup) { | |
nextSetup = caseSetup; | |
} | |
String getSplitValue(String data, char separator, int index) | |
{ | |
int found = 0; | |
int strIndex[] = {0, -1}; | |
int maxIndex = data.length() - 1; | |
for (int i = 0; i <= maxIndex && found <= index; i++) { | |
if (data.charAt(i) == separator || i == maxIndex) { | |
found++; | |
strIndex[0] = strIndex[1] + 1; | |
strIndex[1] = (i == maxIndex) ? i + 1 : i; | |
} | |
} | |
return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; | |
} | |
void pulseRateOxygen() | |
{ | |
long irValue = particleSensor.getIR(); | |
if (checkForBeat(irValue) == true) | |
{ | |
//We sensed a beat! | |
Serial.println("Sensed a beat!"); | |
long delta = millis() - lastBeat; | |
lastBeat = millis(); | |
beatsPerMinute = 60 / (delta / 1000.0); | |
if (beatsPerMinute < 255 && beatsPerMinute > 20) | |
{ | |
rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array | |
rateSpot %= RATE_SIZE; //Wrap variable | |
//Take average of readings | |
beatAvg = 0; | |
for (byte x = 0 ; x < RATE_SIZE ; x++) | |
beatAvg += rates[x]; | |
beatAvg /= RATE_SIZE; | |
} | |
delay(50); | |
} | |
Serial.print("IR="); | |
Serial.print(irValue); | |
Serial.print(", BPM="); | |
Serial.print(beatsPerMinute); | |
Serial.print(", Avg BPM="); | |
Serial.print(beatAvg); | |
if (irValue < 50000) { | |
Serial.print(" No finger?"); | |
beatsPerMinute = 0; | |
beatAvg = 0; | |
} | |
if (beatAvg > 39) { | |
Serial.println("yords!! STOP!"); | |
person.PulseRateAVG = beatAvg; | |
person.PulseRateBPM = beatsPerMinute; | |
hasPulseRate = true; | |
} | |
Serial.println(); | |
} | |
void loopOL() { | |
bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps | |
//read the first 100 samples, and determine the signal range | |
for (byte i = 0 ; i < bufferLength ; i++) | |
{ | |
while (particleSensor.available() == false) //do we have new data? | |
particleSensor.check(); //Check the sensor for new data | |
redBuffer[i] = particleSensor.getRed(); | |
irBuffer[i] = particleSensor.getIR(); | |
particleSensor.nextSample(); //We're finished with this sample so move to next sample | |
Serial.print(F("red=")); | |
Serial.print(redBuffer[i], DEC); | |
Serial.print(F(", ir=")); | |
Serial.println(irBuffer[i], DEC); | |
} | |
//calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples) | |
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate); | |
//Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second | |
while (1) | |
{ | |
//dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top | |
for (byte i = 25; i < 100; i++) | |
{ | |
redBuffer[i - 25] = redBuffer[i]; | |
irBuffer[i - 25] = irBuffer[i]; | |
} | |
//take 25 sets of samples before calculating the heart rate. | |
for (byte i = 75; i < 100; i++) | |
{ | |
while (particleSensor.available() == false) //do we have new data? | |
particleSensor.check(); //Check the sensor for new data | |
digitalWrite(readLED, !digitalRead(readLED)); //Blink onboard LED with every data read | |
redBuffer[i] = particleSensor.getRed(); | |
irBuffer[i] = particleSensor.getIR(); | |
particleSensor.nextSample(); //We're finished with this sample so move to next sample | |
//send samples and calculation result to terminal program through UART | |
Serial.print(F("red=")); | |
Serial.print(redBuffer[i], DEC); | |
Serial.print(F(", ir=")); | |
Serial.print(irBuffer[i], DEC); | |
Serial.print(F(", HR=")); | |
Serial.print(heartRate, DEC); | |
Serial.print(F(", HRvalid=")); | |
Serial.print(validHeartRate, DEC); | |
Serial.print(F(", SPO2=")); | |
Serial.print(spo2, DEC); | |
Serial.print(F(", SPO2Valid=")); | |
Serial.println(validSPO2, DEC); | |
if ( spo2 >= 70 ) { | |
readOL = false; | |
Serial.print(spo2); | |
Serial.println("\t -- oyoyo"); | |
person.OxygenLevel = spo2; | |
// hasOxygenLevel = true; | |
break; | |
} | |
} | |
// | |
if (!readOL) { | |
hasOxygenLevel = true; | |
break; | |
} | |
//After gathering 25 new samples recalculate HR and SP02 | |
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate); | |
} | |
} | |
char BPmygetchar(void) | |
{ //receive serial character from sensor (blocking while nothing received) | |
while (!Serial1.available()); | |
return Serial1.read(); | |
} | |
void loopBP() { | |
// ch = BPmygetchar(); //loop till character received | |
// if(ch==0x0A) // if received character is , 0x0A, 10 then process buffer | |
// { | |
// pos = 0; // buffer position reset for next reading | |
// | |
// // extract data from serial buffer to 8 bit integer value | |
// // convert data from ASCII to decimal | |
// read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0'); | |
// read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0'); | |
// read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0'); | |
// | |
// // Do whatever you wish to do with this sensor integer variables | |
// // Show on LCD or Do some action as per your application | |
// // Value of variables will be between 0-255 | |
// | |
// // example: send demo output to serial monitor on "Serial" | |
// Serial.print(read1); | |
// Serial.print('\t'); | |
// Serial.print(read2); | |
// Serial.print('\t'); | |
// Serial.print(read3); | |
// Serial.print('\t'); | |
// Serial.println(); | |
// Serial.println("AWEW!!!"); | |
// | |
// String bpwew = ""; | |
// bpwew.concat(read1); | |
// bpwew.concat(" "); | |
// bpwew.concat(read2); | |
// Serial.println(bpwew); | |
// person.BP = bpwew; | |
// String prwew = ""; | |
// prwew.concat(read3); | |
// prwew.concat(" per min"); | |
// Serial.println(prwew); | |
// person.PulseRate = prwew; | |
// hasBP = true; | |
// | |
// | |
// | |
// } else { //store serial data to buffer | |
// sbuffer[pos] = ch; | |
// pos++; | |
// } | |
if (mySerial.available()) { | |
String rec = mySerial.readString(); | |
const String data1 = getSplitValue(rec, ' ', 0); | |
const String data2 = getSplitValue(rec, ' ', 1); | |
const String data3 = getSplitValue(rec, ' ', 2); | |
person.BP = data1 + " " + data2; | |
person.PulseRate = data3 + " per min"; | |
Serial.println(rec); | |
Serial.println(data1); | |
Serial.println(data2); | |
Serial.println(data3); | |
Serial.print("BP: "); | |
Serial.print(person.BP); | |
Serial.print("\t Pulse rate: "); | |
Serial.print(person.PulseRate); | |
Serial.println(); | |
hasBP = true; | |
} | |
} | |
float loopWeight() { | |
// Weight Start | |
static boolean newDataReady = 0; | |
const int serialPrintInterval = 0; //increase value to slow down serial print activity | |
// check for new data/start next conversion: | |
if (LoadCell.update()) newDataReady = true; | |
// get smoothed value from the dataset: | |
if (newDataReady) { | |
if (millis() > Masst + serialPrintInterval) { | |
float i = LoadCell.getData(); | |
// Serial.print("Load_cell output val: "); | |
// Serial.println(i); | |
newDataReady = 0; | |
Masst = millis(); | |
return i; | |
// person.Weight = i; | |
// hasWeight = true; | |
} | |
} | |
// receive command from serial terminal, send 't' to initiate tare operation: | |
if (Serial.available() > 0) { | |
char inByte = Serial.read(); | |
if (inByte == 't') LoadCell.tareNoDelay(); | |
} | |
// check if last tare operation is complete: | |
if (LoadCell.getTareStatus() == true) { | |
Serial.println("Tare complete"); | |
} // Weight END | |
} | |
void loopHeight() { | |
// Height Start | |
// Clears the trigPin condition | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); | |
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
// Reads the echoPin, returns the sound wave travel time in microseconds | |
duration = pulseIn(echoPin, HIGH); | |
// Calculating the distance | |
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back) | |
// Displays the distance on the Serial Monitor | |
Serial.println(distance); | |
delay(50); | |
if (distance > 2 && distance < 200) { | |
float distances[10]; | |
int totDistances[10] = {0,0,0,0,0,0,0,0,0,0}; | |
for (int i = 0; i < 10; i++) { | |
// store to weights array; | |
distances[i] = distance; | |
Serial.println(distance); | |
delay(100); | |
} | |
for (int i = 0; i < 10; i++) { | |
for (int j = 0; j < 10; j++) { | |
if ( round(distances[i]) == round(distances[j]) ) { | |
totDistances[i]++; | |
} | |
} | |
if (totDistances[i] == 10) { | |
Serial.println("Got The Best Value!"); | |
float sumDistance; | |
for (int k = 0; k < 10; k++) { | |
sumDistance += distances[k]; | |
Serial.print(String(distances[k]) + ","); | |
} | |
Serial.println(); | |
distance = sumDistance / 10; | |
Serial.println("Distance is = "+String(distance) + " cm"); | |
delay(1000); | |
double totalDistance = 213.36 - distance; | |
Serial.println(totalDistance); | |
double inchesTotal = totalDistance / 2.54; | |
int ft = inchesTotal / 12; | |
double inches = inchesTotal - (12 * ft); | |
String measuredHeight = ""; | |
measuredHeight.concat(ft); | |
measuredHeight.concat(" ft "); | |
measuredHeight.concat(inches); | |
measuredHeight.concat(" in"); | |
Serial.print("Distance: "); | |
Serial.print(distance); | |
Serial.println(" cm"); | |
Serial.print("Measured Height: "); | |
Serial.println(measuredHeight); | |
if (ft <= 7) { | |
person.Height = measuredHeight; | |
if (person.Height.length() > 0) { | |
person.metricHeight = (213.36 - distance) * 0.01; | |
hasHeight = true; | |
} | |
} | |
goto distanceOut; | |
} | |
} | |
distanceOut: | |
Serial.println("Distance Bailout!"); | |
for( int i = 0; i < 10; i++) { | |
Serial.print(String(totDistances[i]) + ","); | |
} | |
Serial.println(); | |
for( int i = 0; i < 10; i++) { | |
Serial.print(String(distances[i]) + ","); | |
} | |
Serial.println(); | |
} | |
// Height END | |
} | |
void loopTemp() { | |
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); Serial.print("\xC2\xB0"); | |
Serial.print("C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.print("\xC2\xB0"); | |
Serial.println("C"); | |
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); Serial.print("c"); | |
Serial.print("F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.print("\xC2\xB0"); | |
Serial.println("F"); | |
Serial.println(); | |
delay(1000); | |
Serial.println(mlx.readObjectTempC()); | |
if ( mlx.readObjectTempC() > 34 ) { | |
person.BodyTemperature = mlx.readObjectTempC(); | |
} | |
if (person.BodyTemperature.length() > 1) { | |
hasTemp = true; | |
} | |
} | |
//#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment