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

99 lines
2.6 KiB
C
Raw Normal View History

2022-12-30 11:29:07 -05:00
#pragma once
//
// FILE: AtomicWeight.h
// AUTHOR: Rob Tillaart
// DATE: 2022-03-09
2023-04-15 14:15:18 -04:00
// VERSION: 0.2.0
2022-12-30 11:29:07 -05:00
// PURPOSE: Arduino library for atomic weights
// URL: https://github.com/RobTillaart/AtomicWeight
#include "Arduino.h"
2023-04-15 14:15:18 -04:00
#define ATOMIC_WEIGHT_LIB_VERSION (F("0.2.0"))
2023-04-14 07:34:00 -04:00
#ifndef ATOMIC_WEIGHT_MAX_SPLIT_LIST
#define ATOMIC_WEIGHT_MAX_SPLIT_LIST 20
#endif
2022-12-30 11:29:07 -05:00
2023-04-15 14:15:18 -04:00
// Miscellaneous related constants.
const float AVOGADRO = 6.02214076e+23; // 1.0 / DALTON.
const float DALTON = 1.66053907e-24; // weight in grams of one nucleon.
const float ELEKTRON_VOLT_JOULE = 1.602176565e-19; // eV in Joule
const float ELEKTRON_VOLT_GRAM = 1.7826619e-39; // eV in grams
const float DALTON_EV = DALTON / ELEKTRON_VOLT_GRAM;
const float DALTON_JOULE = DALTON / ELEKTRON_VOLT_JOULE;
2022-12-30 11:29:07 -05:00
/////////////////////////////////////////////////////////////////////////
//
2022-12-31 12:30:42 -05:00
// PERIODIC TABLE OF ELEMENTS Class
2022-12-30 11:29:07 -05:00
//
class PTOE
{
public:
2023-01-02 07:02:36 -05:00
PTOE(const uint8_t size = 118); // all by default
2022-12-31 11:38:51 -05:00
uint8_t size();
2023-04-15 14:15:18 -04:00
// BASIC
char * name(const uint8_t el);
uint8_t find(const char * abbrev);
2023-01-02 07:02:36 -05:00
uint8_t electrons(const uint8_t el);
uint8_t neutrons(const uint8_t el);
uint8_t protons(const uint8_t el);
2022-12-30 11:29:07 -05:00
2023-04-15 14:15:18 -04:00
// WEIGHT of one atom
2023-04-12 10:52:57 -04:00
float weight(const uint8_t el);
2023-01-02 07:02:36 -05:00
// if (el != NULL) weights one element in a formula, e.g el == "H"
// if (el == NULL) weights the whole formula
2023-04-14 07:34:00 -04:00
float weight(const char * formula, const char * abbrev = NULL);
2023-01-02 07:02:36 -05:00
// mass percentage of one element in a formula.
2023-04-14 07:34:00 -04:00
float massPercentage(const char * formula, const char * abbrev);
2022-12-30 11:29:07 -05:00
2023-04-12 10:52:57 -04:00
2023-04-14 07:34:00 -04:00
// CONVERSION
float moles2grams(const char * formula, float moles = 1.0);
float grams2moles(const char * formula, float grams = 1.0);
2023-04-12 10:52:57 -04:00
// SPLIT FORMULA IN ELEMENTS
uint8_t splitElements(const char * formula);
uint8_t element(uint8_t el);
2023-04-15 14:15:18 -04:00
// COUNT
2023-04-12 10:52:57 -04:00
// if (el != NULL) count atoms of one element in a formula, e.g el == "H"
// if (el == NULL) count all atoms in the whole formula
uint32_t count(const char * formula, const char * el = NULL);
// atom percentage of one element in a formula.
float atomPercentage(const char * formula, const char * el);
2023-04-15 14:15:18 -04:00
// DEBUG
float weightFactor();
2022-12-30 11:29:07 -05:00
private:
uint8_t _size;
2023-04-12 10:52:57 -04:00
2023-01-02 07:02:36 -05:00
// if (el == NULL) ==> whole weight otherwise only of element.
2023-04-14 07:34:00 -04:00
float _weight(char sep, const char * abbrev);
uint32_t _count(const char sep, const char * abbrev);
2023-04-12 10:52:57 -04:00
char *p; // for _weight() and _count()
// for splitElements
2023-04-14 07:34:00 -04:00
uint8_t _splitList[ATOMIC_WEIGHT_MAX_SPLIT_LIST]; // default 20
2023-04-12 10:52:57 -04:00
uint8_t _found;
2022-12-30 11:29:07 -05:00
};
2023-04-12 10:52:57 -04:00
// -- END OF FILE --
2022-12-30 11:29:07 -05:00