2021-01-29 06:31:58 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: weight.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-27 05:13:09 -05:00
|
|
|
// VERSION: 0.1.4
|
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
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
|
|
|
|
2022-11-27 05:13:09 -05:00
|
|
|
#define WEIGHT_LIB_VERSION (F("0.1.4"))
|
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; };
|
|
|
|
|
|
|
|
|
2022-11-27 05:13:09 -05:00
|
|
|
// returns kilo
|
2021-01-29 06:31:58 -05:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-11-27 05:13:09 -05:00
|
|
|
// returns lbs;
|
2021-01-29 06:31:58 -05:00
|
|
|
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
|
|
|
|