mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.1.0 AtomicWeight
This commit is contained in:
parent
38d94e1113
commit
74daa8b597
28
libraries/AtomicWeight/.arduino-ci.yml
Normal file
28
libraries/AtomicWeight/.arduino-ci.yml
Normal file
@ -0,0 +1,28 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
4
libraries/AtomicWeight/.github/FUNDING.yml
vendored
Normal file
4
libraries/AtomicWeight/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
13
libraries/AtomicWeight/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/AtomicWeight/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/AtomicWeight/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/AtomicWeight/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/AtomicWeight/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/AtomicWeight/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
191
libraries/AtomicWeight/AtomicWeight.h
Normal file
191
libraries/AtomicWeight/AtomicWeight.h
Normal file
@ -0,0 +1,191 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: AtomicWeight.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-03-09
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for atomic weights
|
||||
// URL: https://github.com/RobTillaart/AtomicWeight
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define ATOMIC_WEIGHT_LIB_VERSION (F("0.1.0"))
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// list of elements
|
||||
// weight = weight * 222.909
|
||||
//
|
||||
struct element
|
||||
{
|
||||
char name[3];
|
||||
uint16_t weight;
|
||||
}
|
||||
elements[119] =
|
||||
{
|
||||
{"n", 225}, // neutronium
|
||||
{"H", 225},
|
||||
{"He", 892},
|
||||
{"Li", 2186},
|
||||
{"Be", 2009},
|
||||
{"B", 2410},
|
||||
{"C", 2677},
|
||||
{"N", 3122},
|
||||
{"O", 3566},
|
||||
{"F", 4235},
|
||||
{"Ne", 4498},
|
||||
{"Na", 5125},
|
||||
{"Mg", 5418},
|
||||
{"Al", 6014},
|
||||
{"Si", 6261},
|
||||
{"P", 6904},
|
||||
{"S", 7148},
|
||||
{"Cl", 7903},
|
||||
{"Ar", 8905},
|
||||
{"K", 8715},
|
||||
{"Ca", 8934},
|
||||
{"Sc", 10021},
|
||||
{"Ti", 10670},
|
||||
{"V", 11355},
|
||||
{"Cr", 11590},
|
||||
{"Mn", 12246},
|
||||
{"Fe", 12448},
|
||||
{"Co", 13137},
|
||||
{"Ni", 13083},
|
||||
{"Cu", 14165},
|
||||
{"Zn", 14580},
|
||||
{"Ga", 15542},
|
||||
{"Ge", 16192},
|
||||
{"As", 16701},
|
||||
{"Se", 17601},
|
||||
{"Br", 17811},
|
||||
{"Kr", 18679},
|
||||
{"Rb", 19052},
|
||||
{"Sr", 19531},
|
||||
{"Y", 19818},
|
||||
{"Zr", 20335},
|
||||
{"Nb", 20710},
|
||||
{"Mo", 21386},
|
||||
{"Tc", 21845},
|
||||
{"Ru", 22529},
|
||||
{"Rh", 22939},
|
||||
{"Pd", 23722},
|
||||
{"Ag", 24045},
|
||||
{"Cd", 25057},
|
||||
{"In", 25594},
|
||||
{"Sn", 26462},
|
||||
{"Sb", 27141},
|
||||
{"Te", 28443},
|
||||
{"I", 28288},
|
||||
{"Xe", 29266},
|
||||
{"Cs", 29626},
|
||||
{"Ba", 30611},
|
||||
{"La", 30963},
|
||||
{"Ce", 31233},
|
||||
{"Pr", 31410},
|
||||
{"Nd", 32152},
|
||||
{"Pm", 32322},
|
||||
{"Sm", 33517},
|
||||
{"Eu", 33874},
|
||||
{"Gd", 35052},
|
||||
{"Tb", 35426},
|
||||
{"Dy", 36223},
|
||||
{"Ho", 36764},
|
||||
{"Er", 37284},
|
||||
{"Tm", 37657},
|
||||
{"Yb", 38572},
|
||||
{"Lu", 39002},
|
||||
{"Hf", 39787},
|
||||
{"Ta", 40335},
|
||||
{"W", 40980},
|
||||
{"Re", 41507},
|
||||
{"Os", 42404},
|
||||
{"Ir", 42847},
|
||||
{"Pt", 43485},
|
||||
{"Au", 43906},
|
||||
{"Hg", 44713},
|
||||
{"Tl", 45559},
|
||||
{"Pb", 46187},
|
||||
{"Bi", 46584},
|
||||
{"Po", 46588},
|
||||
{"At", 46811},
|
||||
{"Rn", 49486},
|
||||
{"Fr", 49709},
|
||||
{"Ra", 50377},
|
||||
{"Ac", 50600},
|
||||
{"Th", 51723},
|
||||
{"Pa", 51500},
|
||||
{"U", 53059},
|
||||
{"Np", 52829},
|
||||
{"Pu", 54390},
|
||||
{"Am", 54167},
|
||||
{"Cm", 55059},
|
||||
{"Bk", 55059},
|
||||
{"Cf", 55950},
|
||||
{"Es", 56173},
|
||||
{"Fm", 57288},
|
||||
{"Md", 57511},
|
||||
{"No", 57733},
|
||||
{"Lr", 58402},
|
||||
{"Rf", 58179},
|
||||
{"Db", 58402},
|
||||
{"Sg", 59294},
|
||||
{"Bh", 58848},
|
||||
{"Hs", 61746},
|
||||
{"Mt", 59740},
|
||||
{"Ds", 62637},
|
||||
{"Rg", 60631},
|
||||
{"Cn", 63529},
|
||||
{"Nh", 63752},
|
||||
{"Fl", 64421},
|
||||
{"Mc", 64421},
|
||||
{"Lv", 65312},
|
||||
{"Ts", 65535},
|
||||
{"Og", 65535},
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IS THIS THE RIGHT FORMAT?
|
||||
// or should we build a list of elements
|
||||
//
|
||||
class PTOE
|
||||
{
|
||||
public:
|
||||
PTOE(uint8_t size = 118) { _size = size; }; // all by default
|
||||
|
||||
uint8_t size() { return _size; };
|
||||
|
||||
uint8_t electrons(uint8_t el) { return el; };
|
||||
uint8_t neutrons(uint8_t el) { return round(weight(el) - el); };
|
||||
uint8_t protons(uint8_t el) { return el; };
|
||||
|
||||
float weight(uint8_t el) { return elements[el - 1].weight * _weightFactor; };
|
||||
|
||||
char * name(uint8_t el) { return elements[el - 1].name; };
|
||||
uint8_t find(char * abbrev)
|
||||
{
|
||||
for (uint8_t i = 0; i < _size; i++)
|
||||
{
|
||||
if (strcmp(elements[i].name, abbrev) == 0) return i;
|
||||
}
|
||||
return 255;
|
||||
}
|
||||
|
||||
|
||||
// DEBUG
|
||||
float weightFactor() { return _weightFactor; };
|
||||
|
||||
|
||||
private:
|
||||
uint8_t _size;
|
||||
const float _weightFactor = 1.0 / 222.909;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
20
libraries/AtomicWeight/CHANGELOG.md
Normal file
20
libraries/AtomicWeight/CHANGELOG.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Change Log AtomicWeight
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.0] - 2022-12-30
|
||||
- initial release
|
||||
- renamed class from AtomicWeight to PTOE.
|
||||
- add **find(abbrev)**
|
||||
- add examples.
|
||||
- update readme.md.
|
||||
|
||||
|
||||
----
|
||||
|
||||
## [0.0.1] - 2022-03-09
|
||||
- first light (not released)
|
21
libraries/AtomicWeight/LICENSE
Normal file
21
libraries/AtomicWeight/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-2023 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
87
libraries/AtomicWeight/README.md
Normal file
87
libraries/AtomicWeight/README.md
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/AtomicWeight/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/AtomicWeight/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AtomicWeight/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/AtomicWeight/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AtomicWeight/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AtomicWeight/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AtomicWeight.svg?maxAge=3600)](https://github.com/RobTillaart/AtomicWeight/releases)
|
||||
|
||||
|
||||
# AtomicWeight
|
||||
|
||||
Arduino library for atomic weights.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
This library is mainly as a base for educational purposes.
|
||||
Learning the periodic table of elements, the abbreviations and weight.
|
||||
It also provides the number of electrons, neutrons and protons per element.
|
||||
|
||||
#### internal
|
||||
|
||||
Table uses compressed weight to save RAM
|
||||
- store weight as **uint16_t**, 0..65535
|
||||
- weight factor = 222.909 = (65535.0 / heaviest element=118)
|
||||
- error < 0.5%
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "AtomicWeight.h"
|
||||
```
|
||||
|
||||
- **PTOE()** Constructor (Periodic Table Of Elements)
|
||||
- **uint8_t electrons(uint8_t element)** returns the number of electrons of the element.
|
||||
- **uint8_t neutrons(uint8_t element)** returns the number of neutrons of the element.
|
||||
- **uint8_t protons(uint8_t element)** returns the number of protons of the element.
|
||||
- **float weight(uint8_t element)** returns the weight of the element. (error < 0.5%, table uses "weight compression")
|
||||
- **uint8_t find(char \* abbreviation)** returns the element number.
|
||||
- **char \* name(uint8_t element)** returns the abbreviation of element.
|
||||
|
||||
|
||||
#### debug
|
||||
|
||||
- **float weightFactor()** returns weightFactor.
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See examples
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
|
||||
- improve documentation
|
||||
- add examples
|
||||
|
||||
#### should
|
||||
|
||||
- state table
|
||||
- liquid, gas, solid, unknown (2 bits per element) = ~30 bytes
|
||||
- (short) table of English names
|
||||
- which ones ?
|
||||
- move code to .cpp file
|
||||
- parameters element should be less than _size
|
||||
|
||||
#### could
|
||||
|
||||
- extend unit tests
|
||||
- function weight("H2O") => 18
|
||||
- easier to parse with separator: weight("C6 H6 O6 ")
|
||||
|
||||
#### wont (unless)
|
||||
|
||||
- more information?
|
||||
- Electron bands K L M etc?
|
||||
- database needed
|
||||
- temperatures,
|
||||
- melt
|
||||
- evaporate
|
||||
- 2 bytes per temp 4 x 118 = 476 bytes
|
||||
- compression 3 bytes for 2 temps 2x 12 bits = 0..4095 K = 354 bytes
|
||||
|
||||
|
||||
|
144
libraries/AtomicWeight/elements_float.h
Normal file
144
libraries/AtomicWeight/elements_float.h
Normal file
@ -0,0 +1,144 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: elements_float.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-03-09
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: list of weights
|
||||
// URL: https://github.com/RobTillaart/AtomicWeight
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// float periodic table
|
||||
//
|
||||
struct element
|
||||
{
|
||||
char name[3];
|
||||
float weight;
|
||||
}
|
||||
elements[119] =
|
||||
{
|
||||
{"n", 1.00794}, // neutronium
|
||||
{"H" , 1.00794},
|
||||
{"He", 4.002602},
|
||||
{"Li", 9.80665},
|
||||
{"Be", 9.012182},
|
||||
{"B" , 10.811},
|
||||
{"C" , 12.0107},
|
||||
{"N" , 14.0067},
|
||||
{"O" , 15.9994},
|
||||
{"F" , 18.9984032},
|
||||
{"Ne", 20.1797},
|
||||
{"Na", 22.989770},
|
||||
{"Mg", 24.3050},
|
||||
{"Al", 26.981538},
|
||||
{"Si", 28.0855},
|
||||
{"P" , 30.973761},
|
||||
{"S" , 32.065},
|
||||
{"Cl", 35.453},
|
||||
{"Ar", 39.948},
|
||||
{"K" , 39.0983},
|
||||
{"Ca", 40.078},
|
||||
{"Sc", 44.955910},
|
||||
{"Ti", 47.867},
|
||||
{"V" , 50.9415},
|
||||
{"Cr", 51.9961},
|
||||
{"Mn", 54.938049},
|
||||
{"Fe", 55.845},
|
||||
{"Co", 58.933200},
|
||||
{"Ni", 58.6934},
|
||||
{"Cu", 63.546},
|
||||
{"Zn", 65.409},
|
||||
{"Ga", 69.723},
|
||||
{"Ge", 72.64},
|
||||
{"As", 74.92160},
|
||||
{"Se", 78.96},
|
||||
{"Br", 79.904},
|
||||
{"Kr", 83.798},
|
||||
{"Rb", 85.4678},
|
||||
{"Sr", 87.62},
|
||||
{"Y" , 88.90585},
|
||||
{"Zr", 91.224},
|
||||
{"Nb", 92.90638},
|
||||
{"Mo", 95.94},
|
||||
{"Tc", 98},
|
||||
{"Ru", 101.07},
|
||||
{"Rh", 102.90550},
|
||||
{"Pd", 106.42},
|
||||
{"Ag", 107.8682},
|
||||
{"Cd", 112.411},
|
||||
{"In", 114.818},
|
||||
{"Sn", 118.710},
|
||||
{"Sb", 121.760},
|
||||
{"Te", 127.60},
|
||||
{"I" , 126.90447},
|
||||
{"Xe", 131.293},
|
||||
{"Cs", 132.90545},
|
||||
{"Ba", 137.327},
|
||||
{"La", 138.9055},
|
||||
{"Ce", 140.116},
|
||||
{"Pr", 140.90765},
|
||||
{"Nd", 144.24},
|
||||
{"Pm", 145},
|
||||
{"Sm", 150.36},
|
||||
{"Eu", 151.964},
|
||||
{"Gd", 157.25},
|
||||
{"Tb", 158.92534},
|
||||
{"Dy", 162.500},
|
||||
{"Ho", 164.93032},
|
||||
{"Er", 167.259},
|
||||
{"Tm", 168.93421},
|
||||
{"Yb", 173.04},
|
||||
{"Lu", 174.967},
|
||||
{"Hf", 178.49},
|
||||
{"Ta", 180.9479},
|
||||
{"W" , 183.84},
|
||||
{"Re", 186.207},
|
||||
{"Os", 190.23},
|
||||
{"Ir", 192.217},
|
||||
{"Pt", 195.078},
|
||||
{"Au", 196.96655},
|
||||
{"Hg", 200.59},
|
||||
{"Tl", 204.3833},
|
||||
{"Pb", 207.2},
|
||||
{"Bi", 208.98038},
|
||||
{"Po", 209},
|
||||
{"At", 210},
|
||||
{"Rn", 222},
|
||||
{"Fr", 223},
|
||||
{"Ra", 226},
|
||||
{"Ac", 227},
|
||||
{"Th", 232.0381},
|
||||
{"Pa", 231.03588},
|
||||
{"U" , 238.02891},
|
||||
{"Np", 237},
|
||||
{"Pu", 244},
|
||||
{"Am", 243},
|
||||
{"Cm", 247},
|
||||
{"Bk", 247},
|
||||
{"Cf", 251},
|
||||
{"Es", 252},
|
||||
{"Fm", 257},
|
||||
{"Md", 258},
|
||||
{"No", 259},
|
||||
{"Lr", 262},
|
||||
{"Rf", 261},
|
||||
{"Db", 262},
|
||||
{"Sg", 266},
|
||||
{"Bh", 264},
|
||||
{"Hs", 277},
|
||||
{"Mt", 268},
|
||||
{"Ds", 281},
|
||||
{"Rg", 272},
|
||||
{"Cn", 285},
|
||||
{"Nh", 286},
|
||||
{"Fl", 289},
|
||||
{"Mc", 289},
|
||||
{"Lv", 293},
|
||||
{"Ts", 294},
|
||||
{"Og", 294}
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,33 @@
|
||||
// FILE: atomic_weight_find.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/AtomicWeight
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "AtomicWeight.h"
|
||||
|
||||
PTOE ptoe;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
uint8_t n = ptoe.find("Fe");
|
||||
Serial.println(ptoe.protons(n));
|
||||
|
||||
n = ptoe.find("Au");
|
||||
Serial.println(ptoe.protons(n));
|
||||
|
||||
n = ptoe.find("H");
|
||||
Serial.println(ptoe.protons(n));
|
||||
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,48 @@
|
||||
// FILE: atomic_weight_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/AtomicWeight
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "AtomicWeight.h"
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
PTOE ptoe;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
for (int i = 0; i <= ptoe.size(); i++)
|
||||
{
|
||||
printElem(i);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void printElem(uint8_t i)
|
||||
{
|
||||
Serial.print(ptoe.name(i));
|
||||
Serial.print("\t");
|
||||
Serial.print(ptoe.electrons(i));
|
||||
Serial.print("\t");
|
||||
Serial.print(ptoe.protons(i));
|
||||
Serial.print("\t");
|
||||
Serial.print(ptoe.neutrons(i));
|
||||
Serial.print("\t");
|
||||
Serial.print(ptoe.weight(i), 3);
|
||||
|
||||
Serial.print("\n");
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,143 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: elements_float.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-03-09
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: list of weights
|
||||
// URL: https://github.com/RobTillaart/AtomicWeight
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
//
|
||||
struct element
|
||||
{
|
||||
char name[3];
|
||||
float weight;
|
||||
}
|
||||
elements[118] =
|
||||
{
|
||||
{"H" , 1.00794},
|
||||
{"He", 4.002602},
|
||||
{"Li", 9.80665},
|
||||
{"Be", 9.012182},
|
||||
{"B" , 10.811},
|
||||
{"C" , 12.0107},
|
||||
{"N" , 14.0067},
|
||||
{"O" , 15.9994},
|
||||
{"F" , 18.9984032},
|
||||
{"Ne", 20.1797},
|
||||
{"Na", 22.989770},
|
||||
{"Mg", 24.3050},
|
||||
{"Al", 26.981538},
|
||||
{"Si", 28.0855},
|
||||
{"P" , 30.973761},
|
||||
{"S" , 32.065},
|
||||
{"Cl", 35.453},
|
||||
{"Ar", 39.948},
|
||||
{"K" , 39.0983},
|
||||
{"Ca", 40.078},
|
||||
{"Sc", 44.955910},
|
||||
{"Ti", 47.867},
|
||||
{"V" , 50.9415},
|
||||
{"Cr", 51.9961},
|
||||
{"Mn", 54.938049},
|
||||
{"Fe", 55.845},
|
||||
{"Co", 58.933200},
|
||||
{"Ni", 58.6934},
|
||||
{"Cu", 63.546},
|
||||
{"Zn", 65.409},
|
||||
{"Ga", 69.723},
|
||||
{"Ge", 72.64},
|
||||
{"As", 74.92160},
|
||||
{"Se", 78.96},
|
||||
{"Br", 79.904},
|
||||
{"Kr", 83.798},
|
||||
{"Rb", 85.4678},
|
||||
{"Sr", 87.62},
|
||||
{"Y" , 88.90585},
|
||||
{"Zr", 91.224},
|
||||
{"Nb", 92.90638},
|
||||
{"Mo", 95.94},
|
||||
{"Tc", 98},
|
||||
{"Ru", 101.07},
|
||||
{"Rh", 102.90550},
|
||||
{"Pd", 106.42},
|
||||
{"Ag", 107.8682},
|
||||
{"Cd", 112.411},
|
||||
{"In", 114.818},
|
||||
{"Sn", 118.710},
|
||||
{"Sb", 121.760},
|
||||
{"Te", 127.60},
|
||||
{"I" , 126.90447},
|
||||
{"Xe", 131.293},
|
||||
{"Cs", 132.90545},
|
||||
{"Ba", 137.327},
|
||||
{"La", 138.9055},
|
||||
{"Ce", 140.116},
|
||||
{"Pr", 140.90765},
|
||||
{"Nd", 144.24},
|
||||
{"Pm", 145},
|
||||
{"Sm", 150.36},
|
||||
{"Eu", 151.964},
|
||||
{"Gd", 157.25},
|
||||
{"Tb", 158.92534},
|
||||
{"Dy", 162.500},
|
||||
{"Ho", 164.93032},
|
||||
{"Er", 167.259},
|
||||
{"Tm", 168.93421},
|
||||
{"Yb", 173.04},
|
||||
{"Lu", 174.967},
|
||||
{"Hf", 178.49},
|
||||
{"Ta", 180.9479},
|
||||
{"W" , 183.84},
|
||||
{"Re", 186.207},
|
||||
{"Os", 190.23},
|
||||
{"Ir", 192.217},
|
||||
{"Pt", 195.078},
|
||||
{"Au", 196.96655},
|
||||
{"Hg", 200.59},
|
||||
{"Tl", 204.3833},
|
||||
{"Pb", 207.2},
|
||||
{"Bi", 208.98038},
|
||||
{"Po", 209},
|
||||
{"At", 210},
|
||||
{"Rn", 222},
|
||||
{"Fr", 223},
|
||||
{"Ra", 226},
|
||||
{"Ac", 227},
|
||||
{"Th", 232.0381},
|
||||
{"Pa", 231.03588},
|
||||
{"U" , 238.02891},
|
||||
{"Np", 237},
|
||||
{"Pu", 244},
|
||||
{"Am", 243},
|
||||
{"Cm", 247},
|
||||
{"Bk", 247},
|
||||
{"Cf", 251},
|
||||
{"Es", 252},
|
||||
{"Fm", 257},
|
||||
{"Md", 258},
|
||||
{"No", 259},
|
||||
{"Lr", 262},
|
||||
{"Rf", 261},
|
||||
{"Db", 262},
|
||||
{"Sg", 266},
|
||||
{"Bh", 264},
|
||||
{"Hs", 277},
|
||||
{"Mt", 268},
|
||||
{"Ds", 281},
|
||||
{"Rg", 272},
|
||||
{"Cn", 285},
|
||||
{"Nh", 286},
|
||||
{"Fl", 289},
|
||||
{"Mc", 289},
|
||||
{"Lv", 293},
|
||||
{"Ts", 294},
|
||||
{"Og", 294}
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,59 @@
|
||||
// FILE: generate_uint16_table.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// URL: https://github.com/RobTillaart/AtomicWeight
|
||||
// PURPOSE: generate the 16 bit table for the AtomicWeight library
|
||||
// instead of a float per element it uses an uint16_t
|
||||
// and a weight factor. The error is less than 0.3%.
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "elements_float.h"
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// generate 16 bit table
|
||||
//
|
||||
|
||||
// HEADER
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println("/////////////////////////////////////////");
|
||||
Serial.println("//");
|
||||
Serial.println("// list of elements ");
|
||||
Serial.println("// weight = weight * (1.0/ 222.909)");
|
||||
Serial.println("//");
|
||||
Serial.println("struct element");
|
||||
Serial.println("{");
|
||||
Serial.println(" // uint8_t nr;");
|
||||
Serial.println(" char name[3];");
|
||||
Serial.println(" uint16_t weight;");
|
||||
Serial.println("}");
|
||||
Serial.println("elements[118] =");
|
||||
|
||||
// ELEMENTS
|
||||
Serial.println("{");
|
||||
for (int i = 0; i < 118; i++)
|
||||
{
|
||||
Serial.print(" {\"");
|
||||
Serial.print(elements[i].name);
|
||||
Serial.print("\", ");
|
||||
Serial.print(round(elements[i].weight * 222.909));
|
||||
Serial.println("},");
|
||||
}
|
||||
Serial.println("};");
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
22
libraries/AtomicWeight/keywords.txt
Normal file
22
libraries/AtomicWeight/keywords.txt
Normal file
@ -0,0 +1,22 @@
|
||||
# Syntax Colouring Map for AtomicWeight
|
||||
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
PTOE KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
size KEYWORD2
|
||||
|
||||
protons KEYWORD2
|
||||
neutrons KEYWORD2
|
||||
electrons KEYWORD2
|
||||
weight KEYWORD2
|
||||
|
||||
name KEYWORD2
|
||||
find KEYWORD2
|
||||
|
||||
|
||||
# Constants ( LITERAL1)
|
||||
ATOMIC_WEIGHT_LIB_VERSION LITERAL1
|
||||
|
23
libraries/AtomicWeight/library.json
Normal file
23
libraries/AtomicWeight/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "AtomicWeight",
|
||||
"keywords": "Mass,atoms,weight,PTOE,periodic,elements",
|
||||
"description": "Arduino library for atomic weights.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AtomicWeight.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"headers": "AtomicWeight.h"
|
||||
}
|
11
libraries/AtomicWeight/library.properties
Normal file
11
libraries/AtomicWeight/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=AtomicWeight
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for AtomicWeight
|
||||
paragraph=Mass,atoms,weight,PTOE,periodic,elements
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/AtomicWeight
|
||||
architectures=*
|
||||
includes=AtomicWeight.h
|
||||
depends=
|
74
libraries/AtomicWeight/test/unit_test_001.cpp
Normal file
74
libraries/AtomicWeight/test/unit_test_001.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-03-09
|
||||
// PURPOSE: unit tests for the AtomicWeight library
|
||||
// https://github.com/RobTillaart/AtomicWeight
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual); // a == b
|
||||
// assertNotEqual(unwanted, actual); // a != b
|
||||
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
||||
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
||||
// assertLess(upperBound, actual); // a < b
|
||||
// assertMore(lowerBound, actual); // a > b
|
||||
// assertLessOrEqual(upperBound, actual); // a <= b
|
||||
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
||||
// assertTrue(actual);
|
||||
// assertFalse(actual);
|
||||
// assertNull(actual);
|
||||
|
||||
// // special cases for floats
|
||||
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
||||
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
||||
// assertInfinity(actual); // isinf(a)
|
||||
// assertNotInfinity(actual); // !isinf(a)
|
||||
// assertNAN(arg); // isnan(a)
|
||||
// assertNotNAN(arg); // !isnan(a)
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
|
||||
#include "AtomicWeight.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "ATOMIC_WEIGHT_LIB_VERSION: %s\n", (char *) ATOMIC_WEIGHT_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constants)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
PTOE ptoe;
|
||||
|
||||
assertEqual(118, ptoe.size());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_find)
|
||||
{
|
||||
PTOE ptoe;
|
||||
|
||||
assertEqual(1, ptoe.find("H"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
Loading…
Reference in New Issue
Block a user