GY-63_MS5611/libraries/GAMMA/README.md

80 lines
3.2 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/GAMMA/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-11-02 10:15:11 -04:00
[![Arduino-lint](https://github.com/RobTillaart/GAMMA/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/GAMMA/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/GAMMA/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/GAMMA/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/GAMMA/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/GAMMA.svg?maxAge=3600)](https://github.com/RobTillaart/GAMMA/releases)
2021-11-02 10:15:11 -04:00
2021-01-29 06:31:58 -05:00
# GAMMA
Arduino Library for the GAMMA function to adjust brightness of LED's etc.
2021-11-02 10:15:11 -04:00
2021-01-29 06:31:58 -05:00
## Description
This library is provides a gamma lookup class. It is typical used to
change the intensity / brightness of a LED to match the human eye.
When a LED is given 50% PWM it looks far brighter for the eye.
This lib provides a balance between an expensive math function and the speed
of a lookup table.
The accuracy of the library depends on the size of the internal array.
A size of 256 is the reference. Smaller arrays use interpolation and
these interpolated values are good (< 1%) down to internal array size 16.
The size can be as small as 2 which is pretty inaccurate.
In this latter case the curve is approximated by only two linear interpolations.
In short, choose the size that fits your application.
2021-11-02 10:15:11 -04:00
The library has a **setGamma(float gamma)** function that allows an application
to change the gamma value runtime.
This allows adjustments that a fixed table does not have.
2021-01-29 06:31:58 -05:00
The class can be used to dump the internal table e.g. to place in PROGMEM.
2021-11-02 10:15:11 -04:00
Note: tested on UNO and ESP32 only.
2021-01-29 06:31:58 -05:00
## Interface
### Core functions
2021-11-02 10:15:11 -04:00
- **GAMMA(uint16_t size = 32)** constructor, gets the size of the internal
array as parameter. The default for size = 32 as this is a good balance between performance
and size of the internal array. The size parameter must be in {2, 4, 8, 16, 32, 64, 128, 256 }.
- **begin()** The array is initialized with a gamma == 2.8 which is an often used value.
**begin()** must be called before any other function.
2021-01-29 06:31:58 -05:00
- **setGamma(float gamma)** calculates and fills the array with new values.
This can be done runtime so runtime adjustment of gamma mapping.
2021-11-02 10:15:11 -04:00
This function takes relative quite some time.
The parameter **gamma** must be > 0. The value 1 gives an 1:1 mapping.
2021-01-29 06:31:58 -05:00
- **getGamma()** returns the set gamma value.
- **operator \[\]** allows the GAMMA object to be accessed as an array.
like ```x = G[40];``` Makes it easy to switch with a real array.
2021-11-02 10:15:11 -04:00
2021-01-29 06:31:58 -05:00
### Development functions
- **size()** returns size of the internal array.
2021-12-18 11:16:37 -05:00
- **distinct()** returns the number of distinct values in the table.
Especially with larger internal tables rhere will be duplicate numbers in the table.
2021-01-29 06:31:58 -05:00
- **dump()** dumps the internal table to Serial. Can be useful to create
2021-11-02 10:15:11 -04:00
an array in RAM, PROGMEM or wherever.
## Operation
See example
2021-01-29 06:31:58 -05:00
## Future ideas
2021-11-02 10:15:11 -04:00
- improve documentation
2021-12-18 11:16:37 -05:00
- test other platforms
2021-01-29 06:31:58 -05:00
- look for optimizations
- uint16 version?
2021-12-18 11:16:37 -05:00
- **dumpAsArray()** - generate a C style array
-