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

69 lines
3.0 KiB
Markdown
Raw Normal View History

2020-11-27 05:10:47 -05:00
2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/BoolArray/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-10-19 08:40:20 -04:00
[![Arduino-lint](https://github.com/RobTillaart/BoolArray/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/BoolArray/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/BoolArray/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/BoolArray/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/BoolArray/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/BoolArray.svg?maxAge=3600)](https://github.com/RobTillaart/BoolArray/releases)
2020-11-27 05:10:47 -05:00
# BoolArray
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
Arduino library for compact array of booleans of max size 2000 (UNO).
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
## Description
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
The BoolArray class allows the user to instantiate an array of booleans, allocating only one bit per element.
For example one could create an array of 1000 throws with a coin. Normally this would take 1000 bytes,
but BoolArray can store one throw in 1 bit, so 1000 throws in approx 125 bytes.
The class is optimized for storage by packing 8 elements of the array in one byte.
You need to check if your application needs more performance than this library can deliver.
The BoolArray library is one from a set of three:
2021-12-14 08:48:42 -05:00
2021-10-19 08:40:20 -04:00
- **BitArray** for elements of user defined size in bits (values 0 .. 2^n-1)
- **BoolArray** for elements of 1 bit (values 0 .. 1)
- **nybbleArray** for elements of 4 bits (values 0 .. 15)
2020-11-27 05:10:47 -05:00
BoolArray is faster than BitArray as it only supports single bits and does not need to merge parts
of different bytes to read/write a value. However BoolArray currently only supports 2000 bits while
BitArray can support more.
2021-01-29 06:31:58 -05:00
## Interface
2021-10-19 08:40:20 -04:00
- **BoolArray()** Constructor
2021-01-29 06:31:58 -05:00
- **~BoolArray()** Destructor
2021-10-19 08:40:20 -04:00
- **uint8_t begin(uint16_t size)** dynamically allocates size elements (8 bools in one byte). Returns **BOOLARRAY_OK** on success.
2021-01-29 06:31:58 -05:00
- **uint16_t size()** returns number of bool elements.
2021-10-19 08:40:20 -04:00
- **uint16_t memory()** returns number of bytes used.
- **uint8_t setAll(uint8_t value)** Sets all elements to false (0) or true (all other values).
- **uint8_t set(uint16_t index, uint8_t value)** Set the element to false (0) or true (all other values).
- **uint8_t get(uint16_t index)** Return 0 or 1 OR an error value which can be interpreted as true.
2021-01-29 06:31:58 -05:00
So one need to check these carefully.
2021-10-19 08:40:20 -04:00
- **uint8_t toggle(uint16_t index)** Toggles element at index. Returns **BOOLARRAY_OK** on success.
2021-01-29 06:31:58 -05:00
- **uint8_t clear()** Sets all elements to false.
## Operation
2020-11-27 05:10:47 -05:00
Check out the examples.
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
## Notes
2021-01-29 06:31:58 -05:00
2021-10-19 08:40:20 -04:00
The BoolArray class allocates dynamic memory.
2020-11-27 05:10:47 -05:00
The **BOOLARRAY_MAXSIZE** is set to 2000, this was chosen as **malloc()** can only allocate 255 bytes
2021-10-19 08:40:20 -04:00
in one call on an UNO. This is not checked with the recent versions of the IDE any more.
2020-11-27 05:10:47 -05:00
The library is tested on AVR architecture only.
2021-10-19 08:40:20 -04:00
## Future
- performance test on ESP32
- performance for **clear()** dedicated loop vs **setAll(0)** call
- update examples.