GY-63_MS5611/libraries/weight/weight.h

66 lines
1.6 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: weight.h
// AUTHOR: Rob Tillaart
2021-12-29 09:51:56 -05:00
// VERSION: 0.1.3
2021-01-29 06:31:58 -05:00
// PURPOSE: Collection weight conversion functions
2021-05-30 08:20:48 -04:00
// URL: https://github.com/RobTillaart/weight
2021-01-29 06:31:58 -05:00
//
// HISTORY:
// 0.1.0 2020-06-16 initial version
2021-12-29 09:51:56 -05:00
// 0.1.1 2021-01-09 add Arduino-CI + unit test
2021-05-30 08:20:48 -04:00
// 0.1.2 2021-01-09 fix URL
2021-12-29 09:51:56 -05:00
// 0.1.3 2021-12-29 update library.json, license, minor edits
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2021-12-29 09:51:56 -05:00
#define WEIGHT_LIB_VERSION (F("0.1.3"))
2021-01-29 06:31:58 -05:00
float lbs2kilo(float lbs) { return lbs * 0.45359237; };
float kilo2lbs(float kilos) { return kilos * 2.20462262; };
float ounce2gram(float ounce) { return ounce * 28.3495231; };
float gram2ounce(float gram) { return gram * 0.03527396195; };
float gram2kilo(float gram) { return gram * 0.001; };
float kilo2gram( float kilo) { return kilo * 1000; };
float lbs2ounce(float lbs) { return lbs * 16; };
float ounce2lbs(float ounce) { return ounce * 0.0625; };
float stone2lbs(float stone) { return stone * 14; };
float lbs2stone(float lbs) { return lbs * 0.0714285714; };
float stone2kilo(float stone) { return stone * 6.35029318; };
float kilo2stone(float kilo) { return kilo * 0.157473044; };
// returns kilo
float US2metric(float stone, float lbs, float ounce)
{
float kilo = stone * 6.35029318;
kilo += lbs * 0.45359237;
kilo += ounce * (0.0625 * 0.45359237);
return kilo;
};
// returns lbs;
float metric2US(float kilo, float &stone, float &lbs, float &ounce)
{
float val = kilo * 2.20462262;
lbs = val;
stone = int(lbs * 0.0714285714);
lbs -= stone * 14;
ounce = (lbs - int(lbs)) * 16;
lbs = int(lbs);
return val;
}
2021-12-29 09:51:56 -05:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-12-29 09:51:56 -05:00