2020-05-20 03:53:04 -04:00
|
|
|
#pragma once
|
2017-08-20 16:11:38 -04:00
|
|
|
// FILE: PinOutGroup.h
|
2021-11-13 09:19:09 -05:00
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-22 07:46:07 -05:00
|
|
|
// VERSION: 0.1.7
|
2020-05-20 03:53:04 -04:00
|
|
|
// DATE: 2017-04-26
|
2017-08-20 16:11:38 -04:00
|
|
|
// PURPOSE: PinOutGroup library for Arduino
|
2021-01-29 06:31:58 -05:00
|
|
|
// URL: https://github.com/RobTillaart/PinOutGroup
|
2020-05-20 03:53:04 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2017-08-20 16:11:38 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-11-22 07:46:07 -05:00
|
|
|
#define PINOUTGROUP_LIB_VERSION (F("0.1.7"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2020-05-20 03:53:04 -04:00
|
|
|
|
|
|
|
// smaller MAXSIZE will reduce memory footprint with ditto bytes.
|
|
|
|
#ifndef PINOUTGROUP_MAXSIZE
|
2021-12-23 12:59:45 -05:00
|
|
|
#define PINOUTGROUP_MAXSIZE 16
|
2022-11-22 07:46:07 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define PINOUTGROUP_ERROR_PIN 0xFF
|
2017-08-20 16:11:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
class PinOutGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PinOutGroup();
|
2022-11-22 07:46:07 -05:00
|
|
|
|
|
|
|
// enables one to reset at he pinGroup and repopulate it
|
2020-05-20 03:53:04 -04:00
|
|
|
void clear();
|
|
|
|
|
2022-11-22 07:46:07 -05:00
|
|
|
// adds a predefined array of pin numbers to the PinOutGroup
|
|
|
|
// sets all to (LOW, HIGH)
|
2021-11-13 09:19:09 -05:00
|
|
|
uint8_t add(uint8_t size, uint8_t* pinArray, uint8_t value = LOW);
|
2022-11-22 07:46:07 -05:00
|
|
|
// adds a single pin to the PinOutGroup, default to LOW.
|
2021-01-29 06:31:58 -05:00
|
|
|
uint8_t add(uint8_t pin, uint8_t value = LOW);
|
|
|
|
|
2022-11-22 07:46:07 -05:00
|
|
|
// returns count of pin in the group => only 0 or 1 makes sense
|
2021-01-29 06:31:58 -05:00
|
|
|
uint8_t isInGroup(uint8_t pin);
|
2017-08-20 16:11:38 -04:00
|
|
|
|
2022-11-22 07:46:07 -05:00
|
|
|
// set up to 16 pins "simultaneously" in one call.
|
2020-05-20 03:53:04 -04:00
|
|
|
uint8_t write(uint16_t value);
|
2022-11-22 07:46:07 -05:00
|
|
|
// write to a single pin while maintaining internal admin
|
2021-11-13 09:19:09 -05:00
|
|
|
uint8_t write(uint8_t index, uint8_t value);
|
2021-01-29 06:31:58 -05:00
|
|
|
void allLOW();
|
|
|
|
void allHIGH();
|
|
|
|
|
2022-11-22 07:46:07 -05:00
|
|
|
// retrieve the last set value
|
2020-05-20 03:53:04 -04:00
|
|
|
uint16_t read() { return _lastValue; };
|
|
|
|
|
2017-08-20 16:11:38 -04:00
|
|
|
uint8_t size() { return _size; };
|
2022-11-22 07:46:07 -05:00
|
|
|
// check how many free "slots" there are...
|
2021-01-29 06:31:58 -05:00
|
|
|
uint8_t available() { return PINOUTGROUP_MAXSIZE - _size; };
|
2021-11-13 09:19:09 -05:00
|
|
|
uint8_t getMaxSize() { return PINOUTGROUP_MAXSIZE; };
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-11-13 09:19:09 -05:00
|
|
|
uint8_t getPin(uint8_t index);
|
|
|
|
uint8_t getIndex(uint8_t pin);
|
2022-11-22 07:46:07 -05:00
|
|
|
|
|
|
|
// obsolete
|
|
|
|
// uint8_t getIdx(uint8_t pin) { return getIndex(pin); };
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2017-08-20 16:11:38 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint16_t _lastValue = 0;
|
2020-05-20 03:53:04 -04:00
|
|
|
uint8_t _pins[PINOUTGROUP_MAXSIZE];
|
2017-08-20 16:11:38 -04:00
|
|
|
uint8_t _size = 0;
|
|
|
|
};
|
2020-05-20 03:53:04 -04:00
|
|
|
|
2021-12-23 12:59:45 -05:00
|
|
|
|
2022-11-22 07:46:07 -05:00
|
|
|
// -- END OF FILE --
|
2021-12-23 12:59:45 -05:00
|
|
|
|