62 lines
1.4 KiB
C
Raw Normal View History

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