mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.3.0 weight
This commit is contained in:
parent
cd94d589b2
commit
4ff96f0da5
@ -1,4 +1,4 @@
|
||||
# Change Log tinySHT2x
|
||||
# Change Log Weight
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
@ -6,11 +6,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.0] - 2023-08-29
|
||||
- rename class **weightConvertor** to **weightConverter**
|
||||
- add **adders** to the weightConverter to add different units of weight.
|
||||
- update readme.md
|
||||
- update keywords.txt
|
||||
- minor edits
|
||||
|
||||
----
|
||||
|
||||
## [0.2.0] - 2022-12-05
|
||||
- add weightConverter class
|
||||
- update readme.md
|
||||
- update unit test
|
||||
|
||||
----
|
||||
|
||||
## [0.1.4] - 2022-11-26
|
||||
- Add RP2040 support to build-CI.
|
||||
|
@ -2,13 +2,16 @@
|
||||
[![Arduino CI](https://github.com/RobTillaart/weight/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/weight/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/weight/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/weight/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/weight/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/weight.svg)](https://github.com/RobTillaart/weight/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/weight/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/weight.svg?maxAge=3600)](https://github.com/RobTillaart/weight/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/weight.svg)](https://registry.platformio.org/libraries/robtillaart/weight)
|
||||
|
||||
|
||||
# Weight
|
||||
|
||||
Library of weight conversion functions.
|
||||
Arduino library to convert weight units.
|
||||
|
||||
|
||||
## Description
|
||||
@ -18,6 +21,13 @@ Weight.h is a library containing weight conversion functions.
|
||||
Open for additions, including obscure weight metrics or
|
||||
weight related math functions and constants.
|
||||
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/AtomicWeight
|
||||
- https://github.com/RobTillaart/VolumeConverter
|
||||
- https://github.com/RobTillaart/HX711
|
||||
- https://github.com/RobTillaart/HX711_MP
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
@ -68,7 +78,10 @@ New conversions are possible by providing a setXYZ and getXYZ() function.
|
||||
These two should convert to and from grams respectively.
|
||||
Additions are welcome, please open an issue.
|
||||
|
||||
Internal representation is the gram as it the standard.
|
||||
Internal representation is the gram as it the ISO standard.
|
||||
|
||||
Since version 0.3.0 the converter can also add different units.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
@ -77,7 +90,7 @@ Internal representation is the gram as it the standard.
|
||||
|
||||
- **weightConverter()**
|
||||
|
||||
#### setters
|
||||
#### Setters
|
||||
|
||||
- **void setKilogram(float value = 0)**
|
||||
- **void setGram(float value = 0)**
|
||||
@ -98,8 +111,28 @@ Internal representation is the gram as it the standard.
|
||||
- **void setGrain(float value = 0)**
|
||||
- **void setCarat(float value = 0)**
|
||||
|
||||
#### Adders
|
||||
|
||||
#### getters
|
||||
- **void addKilogram(float value = 0)**
|
||||
- **void addGram(float value = 0)**
|
||||
- **void addLBS(float value = 0)**
|
||||
- **void addStone(float value = 0)**
|
||||
- **void addOunce(float value = 0)**
|
||||
- **void addLongTonUK(float value = 0)**
|
||||
- **void addShortTonUS(float value = 0)**
|
||||
- **void addQuarterUK(float value = 0)**
|
||||
- **void addQuarterUS(float value = 0)**
|
||||
- **void addSlug(float value = 0)**
|
||||
- **void addTroyPound(float value = 0)**
|
||||
- **void addTroyOunce(float value = 0)**
|
||||
- **void addRobie(float value = 0)**
|
||||
- **void addDram(float value = 0)**
|
||||
- **void addDrachme(float value = 0)**
|
||||
- **void addPoint(float value = 0)**
|
||||
- **void addGrain(float value = 0)**
|
||||
- **void addCarat(float value = 0)**
|
||||
|
||||
#### Getters
|
||||
|
||||
- **float getKilogram()**
|
||||
- **float getGram()**
|
||||
@ -120,32 +153,32 @@ Internal representation is the gram as it the standard.
|
||||
- **float getGrain()**
|
||||
- **float getCarat()**
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
#### Must
|
||||
- improve documentation
|
||||
- where are units used
|
||||
|
||||
#### should
|
||||
#### Should
|
||||
|
||||
|
||||
#### could
|
||||
#### Could
|
||||
- create data types of stone lbs kilo etc.?
|
||||
|
||||
|
||||
#### won't (unless)
|
||||
#### Won't (unless)
|
||||
- large masses - sun planets ? (see relativity library)
|
||||
- gravity constants of planets REL or ABS eg REL_GRAVITY_EARTH 1.0
|
||||
- mass of all elements
|
||||
- an array of floats
|
||||
- a compressed format with access function (1 byte/ element)
|
||||
- constants e.g. MASS_OXYGEN
|
||||
- separate periodicTable.h file ?
|
||||
- molarity functions
|
||||
- mass of common substances.
|
||||
- teaspoon
|
||||
- that is a volume unit.
|
||||
- volume conversion too?
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ void setup()
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
weightConvertor WC;
|
||||
weightConverter WC;
|
||||
|
||||
WC.setKilogram(1);
|
||||
Serial.print(WC.getKilogram(), 4);
|
||||
@ -118,4 +118,5 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -141,5 +141,5 @@ void measure_2()
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -60,5 +60,5 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Syntax Colouring Map For weight
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
weightConvertor KEYWORD1
|
||||
weightConverter KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
@ -44,6 +44,26 @@ setGrain KEYWORD2
|
||||
setCarat KEYWORD2
|
||||
|
||||
|
||||
addKilogram KEYWORD2
|
||||
addGram KEYWORD2
|
||||
addLBS KEYWORD2
|
||||
addStone KEYWORD2
|
||||
addOunce KEYWORD2
|
||||
addLongTonUK KEYWORD2
|
||||
addShortTonUS KEYWORD2
|
||||
addQuarterUK KEYWORD2
|
||||
addQuarterUS KEYWORD2
|
||||
addSlug KEYWORD2
|
||||
addTroyPound KEYWORD2
|
||||
addTroyOunce KEYWORD2
|
||||
addRobie KEYWORD2
|
||||
addDram KEYWORD2
|
||||
addDrachme KEYWORD2
|
||||
addPoint KEYWORD2
|
||||
addGrain KEYWORD2
|
||||
addCarat KEYWORD2
|
||||
|
||||
|
||||
getKilogram KEYWORD2
|
||||
getGram KEYWORD2
|
||||
getLBS KEYWORD2
|
||||
|
@ -13,11 +13,11 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/weight"
|
||||
"url": "https://github.com/RobTillaart/weight.git"
|
||||
},
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "weight.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=weight
|
||||
version=0.2.0
|
||||
version=0.3.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library of weight conversion functions
|
||||
|
@ -126,9 +126,9 @@ unittest(test_US2metric)
|
||||
}
|
||||
|
||||
|
||||
unittest(test_weightConvertor)
|
||||
unittest(test_weightConverter)
|
||||
{
|
||||
weightConvertor WC;
|
||||
weightConverter WC;
|
||||
|
||||
fprintf(stderr, "setKilogram\n");
|
||||
WC.setKilogram(1);
|
||||
@ -206,4 +206,6 @@ unittest(test_weightConvertor)
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: weight.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// VERSION: 0.3.0
|
||||
// PURPOSE: Collection weight conversion functions
|
||||
// URL: https://github.com/RobTillaart/weight
|
||||
|
||||
@ -10,9 +10,13 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define WEIGHT_LIB_VERSION (F("0.2.0"))
|
||||
#define WEIGHT_LIB_VERSION (F("0.3.0"))
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// WEIGHT CONVERSION FUNCTIONS
|
||||
//
|
||||
float lbs2kilo(float lbs) { return lbs * 0.45359237; };
|
||||
float kilo2lbs(float kilos) { return kilos * 2.20462262185; };
|
||||
|
||||
@ -42,7 +46,7 @@ float US2metric(float stone, float lbs, float ounce)
|
||||
};
|
||||
|
||||
|
||||
// returns lbs;
|
||||
// returns lbs
|
||||
float metric2US(float kilo, float &stone, float &lbs, float &ounce)
|
||||
{
|
||||
float val = kilo * 2.20462262185;
|
||||
@ -59,10 +63,10 @@ float metric2US(float kilo, float &stone, float &lbs, float &ounce)
|
||||
//
|
||||
// WEIGHT CONVERTER CLASS
|
||||
//
|
||||
class weightConvertor
|
||||
class weightConverter
|
||||
{
|
||||
public:
|
||||
weightConvertor() { _w = 0; };
|
||||
weightConverter() { _w = 0; };
|
||||
|
||||
// SETTERS
|
||||
void setKilogram(float value = 0) { _w = value * 1000; };
|
||||
@ -84,6 +88,28 @@ public:
|
||||
void setGrain(float value = 0) { _w = value * 0.0647989; };
|
||||
void setCarat(float value = 0) { _w = value * 0.2; };
|
||||
|
||||
|
||||
// ADDERS
|
||||
void addKilogram(float value = 0) { _w += value * 1000; };
|
||||
void addGram(float value = 0) { _w += value; };
|
||||
void addLBS(float value = 0) { _w += value * 453.59237; };
|
||||
void addStone(float value = 0) { _w += value * 6350.29318; };
|
||||
void addOunce(float value = 0) { _w += value * 28.349523125; };
|
||||
void addLongTonUK(float value = 0) { _w += value * 1016046.9088; };
|
||||
void addShortTonUS(float value = 0) { _w += value * 907184.74; };
|
||||
void addQuarterUK(float value = 0) { _w += value * 12700.58636; };
|
||||
void addQuarterUS(float value = 0) { _w += value * 11339.80925; };
|
||||
void addSlug(float value = 0) { _w += value * 14593.903; };
|
||||
void addTroyPound(float value = 0) { _w += value * 373.2417216; };
|
||||
void addTroyOunce(float value = 0) { _w += value * 31.1034768; };
|
||||
void addRobie(float value = 0) { _w += value * 10; };
|
||||
void addDram(float value = 0) { _w += value * 1.77184519531; };
|
||||
void addDrachme(float value = 0) { _w += value * 3.8; };
|
||||
void addPoint(float value = 0) { _w += value * 0.002; };
|
||||
void addGrain(float value = 0) { _w += value * 0.0647989; };
|
||||
void addCarat(float value = 0) { _w += value * 0.2; };
|
||||
|
||||
|
||||
// GETTERS
|
||||
float getKilogram() { return _w * 0.001; }
|
||||
float getGram() { return _w; }
|
||||
@ -109,5 +135,5 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user