2020-05-22 10:00:06 -04:00
|
|
|
#pragma once
|
2017-08-20 16:12:07 -04:00
|
|
|
// FILE: PinInGroup.h
|
|
|
|
// AUTHOR: Rob dot Tillaart at gmail dot com
|
2021-11-12 09:01:35 -05:00
|
|
|
// VERSION: 0.1.5
|
2020-05-22 10:00:06 -04:00
|
|
|
// DATE: 2017-04-26
|
2017-08-20 16:12:07 -04:00
|
|
|
// PURPOSE: PinInGroup library for Arduino
|
|
|
|
// HISTORY: See PinInGroup.cpp
|
|
|
|
//
|
2020-05-22 10:00:06 -04:00
|
|
|
// Note: ESP32 has some dedicated IO pins that cannot be used in a group.
|
|
|
|
// FLASH: pin 6 - 11 (maybe more)
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2020-05-22 10:00:06 -04:00
|
|
|
|
2017-08-20 16:12:07 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-11-12 09:01:35 -05:00
|
|
|
#define PININGROUP_LIB_VERSION (F("0.1.5"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2020-05-22 10:00:06 -04:00
|
|
|
|
|
|
|
// smaller MAXSIZE will reduce memory footprint with ditto bytes.
|
|
|
|
#ifndef PININGROUP_MAXSIZE
|
2021-01-29 06:31:58 -05:00
|
|
|
#define PININGROUP_MAXSIZE 16
|
2020-05-22 10:00:06 -04:00
|
|
|
#endif
|
|
|
|
|
2017-08-20 16:12:07 -04:00
|
|
|
|
|
|
|
class PinInGroup
|
|
|
|
{
|
2021-01-29 06:31:58 -05:00
|
|
|
public:
|
|
|
|
PinInGroup();
|
|
|
|
|
|
|
|
// enables one to reset the pinGroup and repopulate it
|
|
|
|
void clear();
|
|
|
|
|
2021-11-12 09:01:35 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// adds a predefined array of pin numbers to the PinInGroup
|
|
|
|
// sets all to either INPUT (default) or INPUT_PULLUP.
|
2021-11-12 09:01:35 -05:00
|
|
|
uint8_t add(uint8_t size, uint8_t * pinArray, uint8_t mode = INPUT);
|
2021-01-29 06:31:58 -05:00
|
|
|
// adds a single pin to the PinInGroup
|
2021-11-12 09:01:35 -05:00
|
|
|
uint8_t add(uint8_t pin, uint8_t mode = INPUT);
|
|
|
|
|
2020-05-22 10:00:06 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// counts how often a pin is in the group
|
2021-11-12 09:01:35 -05:00
|
|
|
uint8_t isInGroup(uint8_t pin);
|
|
|
|
uint8_t size() { return _size; };
|
|
|
|
uint8_t getMaxSize() { return PININGROUP_MAXSIZE; };
|
|
|
|
// check how many "slots" are available
|
|
|
|
uint8_t available() { return PININGROUP_MAXSIZE - _size; };
|
|
|
|
|
2020-05-22 10:00:06 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// read up to 16 pins "simultaneously" in one call.
|
|
|
|
uint16_t read();
|
|
|
|
// read specific index.
|
2021-11-12 09:01:35 -05:00
|
|
|
uint16_t read(uint8_t index);
|
2020-05-22 10:00:06 -04:00
|
|
|
|
|
|
|
|
2021-11-12 09:01:35 -05:00
|
|
|
uint8_t getPin(uint8_t index);
|
|
|
|
uint8_t getIndex(uint8_t pin);
|
|
|
|
uint8_t getIdx(uint8_t pin) { getIndex(pin); }; // will be obsolete
|
2020-05-22 10:00:06 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
private:
|
|
|
|
uint8_t _pins[PININGROUP_MAXSIZE];
|
|
|
|
uint8_t _size = 0;
|
2017-08-20 16:12:07 -04:00
|
|
|
};
|
2020-05-22 10:00:06 -04:00
|
|
|
|
|
|
|
// -- END OF FILE --
|