2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/HC4067/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/HC4067/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/HC4067/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/HC4067/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/HC4067/actions/workflows/jsoncheck.yml)
|
2023-11-04 09:19:16 -04:00
|
|
|
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/HC4067.svg)](https://github.com/RobTillaart/HC4067/issues)
|
|
|
|
|
2023-01-25 09:35:32 -05:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/HC4067/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/HC4067.svg?maxAge=3600)](https://github.com/RobTillaart/HC4067/releases)
|
2023-11-04 09:19:16 -04:00
|
|
|
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/HC4067.svg)](https://registry.platformio.org/libraries/robtillaart/HC4067)
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
# HC4067
|
|
|
|
|
2023-11-04 09:19:16 -04:00
|
|
|
HC4067 is an Arduino library for a HC4067 1 x 16 channel multiplexer.
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2023-01-25 14:35:04 -05:00
|
|
|
HC4067 is a library to control the CD74HC4067 16 channel
|
|
|
|
multiplexer / demultiplexer and compatible devices.
|
|
|
|
|
|
|
|
The HC4067 allows e.g one analog port read up to 16 different analog channels,
|
|
|
|
or one digital port to read the state of 16 buttons.
|
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
It is also possible to use the HC4067 to select an OUTPUT channel.
|
|
|
|
The signal pin can be connected to VCC (5V) or an IO pin set to OUTPUT.
|
|
|
|
Only the selected channel can show the HIGH level of the IO pin if set to HIGH.
|
|
|
|
Not selected pins will all be set to LOW.
|
2023-01-25 14:35:04 -05:00
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
The channel selection is done with four select lines **S0..S3**.
|
2023-01-25 14:35:04 -05:00
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
The device can be enabled/disabled by the enable line **E**.
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
#### Compatibles
|
|
|
|
|
2023-01-25 14:35:04 -05:00
|
|
|
Not tested, considered compatible.
|
|
|
|
- CD74HC4067, 74HC4067, 74HCT4067
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
|
2023-11-04 09:19:16 -04:00
|
|
|
#### Related
|
|
|
|
|
|
|
|
- https://github.com/RobTillaart/HC4051 (1x8 mux)
|
|
|
|
- https://github.com/RobTillaart/HC4052 (2x4 mux)
|
|
|
|
- https://github.com/RobTillaart/HC4053 (3x2 mux)
|
|
|
|
- https://github.com/RobTillaart/HC4067 (1x16 mux)
|
2024-04-03 13:07:25 -04:00
|
|
|
- https://github.com/RobTillaart/MAX14661 (2x16 mux, I2C)
|
|
|
|
- https://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-analog-multiplexerdemultiplexer/
|
2023-11-04 09:19:16 -04:00
|
|
|
|
|
|
|
|
2023-01-25 09:35:32 -05:00
|
|
|
## Hardware connection
|
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
Typical connection is to connect the four **select pins** to four IO pins of your board.
|
2023-01-25 09:35:32 -05:00
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
The optional **enablePin E** must be connected to **GND** if not used.
|
|
|
|
This way the device will be continuous enabled.
|
2023-01-25 14:35:04 -05:00
|
|
|
|
|
|
|
Example multiplexing analog in.
|
|
|
|
|
|
|
|
```
|
|
|
|
processor HC4067
|
|
|
|
+-------------+ +-------------+
|
|
|
|
| | | |
|
|
|
|
| S0 |------------->| S0 Y0 |
|
|
|
|
| S1 |------------->| S1 Y1 |
|
|
|
|
| S2 |------------->| S2 Y2 |
|
|
|
|
| S3 |------------->| S3 Y3 |
|
|
|
|
| | | Y4 |
|
|
|
|
| E |------------->| Enable Y5 |
|
|
|
|
| | | Y6 |
|
|
|
|
| | | Y7 |
|
|
|
|
| A0 |<-------------| Z Y8 |
|
|
|
|
| | | Y9 |
|
|
|
|
| | | Y10 |
|
|
|
|
| | | Y11 |
|
|
|
|
| | | Y12 |
|
|
|
|
| | | Y13 |
|
|
|
|
| GND |--------------| GND Y14 |
|
|
|
|
| | | VCC Y15 |
|
|
|
|
| | | |
|
|
|
|
+-------------+ +-------------+
|
|
|
|
```
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
#### Less Select lines
|
|
|
|
|
|
|
|
Note: the library does not meant for this mode, although it should work.
|
|
|
|
The GND-ed pins should be set to 255 (not tested).
|
|
|
|
|
|
|
|
It is possible to use less IO pins to connect to the S0..S3.
|
|
|
|
The ones not connected to an IO pin must be connected to GND (preferred).
|
|
|
|
|
|
|
|
| S0 | S1 | S2 | S3 | pins | notes |
|
|
|
|
|:-----:|:-----:|:-----:|:-----:|:------:|:-------:|
|
|
|
|
| IO | IO | IO | IO | 0-15 | default usage
|
|
|
|
| IO | IO | IO | GND | 0-7 |
|
|
|
|
| IO | IO | GND | GND | 0-3 |
|
|
|
|
| IO | GND | GND | GND | 0-1 |
|
|
|
|
|
|
|
|
Of course it is possible to set a Select pin to VCC instead of GND.
|
|
|
|
This will result in another subset of the Y pins to select from.
|
|
|
|
|
|
|
|
|
2023-01-25 09:35:32 -05:00
|
|
|
## Interface
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
#include "HC4067.h"
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Core
|
|
|
|
|
2023-01-25 14:35:04 -05:00
|
|
|
- **HC4067(uint8_t s0, uint8_t s1, uint8_t s2, uint8_t s3, uint8_t enablePin = 255)** constructor.
|
|
|
|
Set the 4 select pins and optional the enable pin.
|
|
|
|
If the enablePin == 255 it is considered not used.
|
|
|
|
- **void setChannel(uint8_t channel)** set the current channel.
|
|
|
|
Valid values 0..15, this value is not checked, only the lower 4 bits will be used.
|
2024-04-03 13:07:25 -04:00
|
|
|
- **uint8_t getChannel()** returns the current channel 0..15.
|
|
|
|
The selected channel is also returned when the multiplexer is disabled.
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
#### Enable
|
|
|
|
|
|
|
|
These functions work only if enablePin is set in the constructor.
|
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
- **void enable()** enables the HC4067 to multiplex.
|
|
|
|
- **void disable()** disables the HC4067, no channel is selected.
|
|
|
|
- **bool isEnabled()** returns the current status of the HC4067.
|
|
|
|
Also returns true if the enablePin is not set in the constructor.
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Future
|
|
|
|
|
|
|
|
#### Must
|
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
- documentation
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
#### Should
|
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
- test performance **setChannel()** on ESP32 / fast board.
|
|
|
|
- should optimized version be AVR only?
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
#### Could
|
|
|
|
|
|
|
|
- next() and prev() as channel selector.
|
2024-04-03 13:07:25 -04:00
|
|
|
- what to do with range borders? ==> stop?
|
2023-01-25 09:35:32 -05:00
|
|
|
|
|
|
|
#### Won't (unless requested)
|
|
|
|
|
2024-04-03 13:07:25 -04:00
|
|
|
- check channel in setChannel() ?
|
|
|
|
- return true if in range, false otherwise.
|
|
|
|
- move code to .cpp file
|
2023-01-25 09:35:32 -05:00
|
|
|
|
2023-11-04 09:19:16 -04:00
|
|
|
|
|
|
|
## Support
|
|
|
|
|
|
|
|
If you appreciate my libraries, you can support the development and maintenance.
|
|
|
|
Improve the quality of the libraries by providing issues and Pull Requests, or
|
|
|
|
donate through PayPal or GitHub sponsors.
|
|
|
|
|
|
|
|
Thank you,
|
|
|
|
|