mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.0 HC4067
This commit is contained in:
parent
6e9bee2b79
commit
7a30666fc6
1
libraries/HC4067/.github/FUNDING.yml
vendored
1
libraries/HC4067/.github/FUNDING.yml
vendored
@ -1,4 +1,5 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
custom: "https://www.paypal.me/robtillaart"
|
||||
|
||||
|
@ -5,8 +5,9 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -6,12 +6,14 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
# sudo sysctl vm.mmap_rnd_bits=28
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
||||
|
@ -9,10 +9,11 @@ on:
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
uses: limitusus/json-syntax-check@v2
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
||||
|
@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.2.0] - 2024-04-03
|
||||
- fix ghost channels when using for OUTPUT
|
||||
- add disable/enable in setChannel()
|
||||
- improve setChannel(), only write changed pins.
|
||||
- update HC4067_performance.ino
|
||||
- update readme.md
|
||||
- update GitHub actions
|
||||
- minor edits
|
||||
|
||||
----
|
||||
|
||||
## [0.1.2] - 2023-11-04
|
||||
- update readme.md
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// FILE: HC4067.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2023-01-25
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: Arduino library for CD74HC4067 1 x 16 channel multiplexer and compatibles.
|
||||
// URL: https://github.com/RobTillaart/HC4067
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define HC4067_LIB_VERSION (F("0.1.2"))
|
||||
#define HC4067_LIB_VERSION (F("0.2.0"))
|
||||
|
||||
|
||||
class HC4067
|
||||
@ -42,16 +42,24 @@ public:
|
||||
|
||||
void setChannel(uint8_t channel)
|
||||
{
|
||||
if ((channel & 0x0F) != _channel)
|
||||
uint8_t _new = channel & 0x0F;
|
||||
if (_new != _channel)
|
||||
{
|
||||
_channel = channel & 0x0F;
|
||||
uint8_t _changed = _new ^ _channel;
|
||||
uint8_t mask = 0x08;
|
||||
uint8_t i = 3;
|
||||
disable(); // prevent ghost channels.
|
||||
while (mask)
|
||||
{
|
||||
digitalWrite(_pins[i--], (mask & _channel));
|
||||
// only write changed pins. // AVR only?
|
||||
if (mask & _changed)
|
||||
{
|
||||
digitalWrite(_pins[i--], (mask & _new));
|
||||
}
|
||||
mask >>= 1;
|
||||
}
|
||||
enable();
|
||||
_channel = _new;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023-2023 Rob Tillaart
|
||||
Copyright (c) 2023-2024 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -22,10 +22,14 @@ 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.
|
||||
|
||||
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.
|
||||
|
||||
The channel selection is done with four select lines **S0..S3**
|
||||
The channel selection is done with four select lines **S0..S3**.
|
||||
|
||||
The device can be enabled/disabled by the enable line **E**
|
||||
The device can be enabled/disabled by the enable line **E**.
|
||||
|
||||
|
||||
#### Compatibles
|
||||
@ -40,14 +44,16 @@ Not tested, considered compatible.
|
||||
- https://github.com/RobTillaart/HC4052 (2x4 mux)
|
||||
- https://github.com/RobTillaart/HC4053 (3x2 mux)
|
||||
- https://github.com/RobTillaart/HC4067 (1x16 mux)
|
||||
- https://github.com/RobTillaart/MAX14661 (2x16 mux, I2C)
|
||||
- https://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-analog-multiplexerdemultiplexer/
|
||||
|
||||
|
||||
## Hardware connection
|
||||
|
||||
Typical connection is to connect the four **select pins** to four IO Pins of your board.
|
||||
Typical connection is to connect the four **select pins** to four IO pins of your board.
|
||||
|
||||
The optional **enablePin E** must be connected to GND if not used.
|
||||
This way the device is continuous enabled.
|
||||
The optional **enablePin E** must be connected to **GND** if not used.
|
||||
This way the device will be continuous enabled.
|
||||
|
||||
Example multiplexing analog in.
|
||||
|
||||
@ -76,6 +82,25 @@ Example multiplexing analog in.
|
||||
```
|
||||
|
||||
|
||||
#### 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.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
@ -89,50 +114,41 @@ 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.
|
||||
- **uint8_t getChannel()** get current channel 0..15.
|
||||
- **uint8_t getChannel()** returns the current channel 0..15.
|
||||
The selected channel is also returned when the multiplexer is disabled.
|
||||
|
||||
|
||||
#### Enable
|
||||
|
||||
These functions work only if enablePin is set in the constructor.
|
||||
|
||||
- **void enable()** idem.
|
||||
- **void disable()** idem.
|
||||
- **bool isEnabled()** idem.
|
||||
Also returns true if enablePin is not set.
|
||||
- **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.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
- elaborate documentation
|
||||
- links etc.
|
||||
|
||||
- documentation
|
||||
|
||||
#### Should
|
||||
|
||||
- optimizations
|
||||
- performance setChannel
|
||||
- investigate how to use with only 3 lines or 2 lines.
|
||||
- set s3 / s2 to LOW always or so
|
||||
|
||||
- test performance **setChannel()** on ESP32 / fast board.
|
||||
- should optimized version be AVR only?
|
||||
|
||||
#### Could
|
||||
|
||||
- next() and prev() as channel selector.
|
||||
- internal channel variable needed.
|
||||
- move code to .cpp file
|
||||
- investigate
|
||||
- can it be used as 16 channel OUTPUT (yes but)
|
||||
- is it buffered?
|
||||
|
||||
- what to do with range borders? ==> stop?
|
||||
|
||||
#### Won't (unless requested)
|
||||
|
||||
- optimizations
|
||||
- only do digitalWrite when changed? gain is minimal.
|
||||
- now takes 24 micros on UNO if set.
|
||||
- check channel in setChannel() ?
|
||||
- return true if in range, false otherwise.
|
||||
- move code to .cpp file
|
||||
|
||||
|
||||
## Support
|
||||
|
@ -7,11 +7,12 @@
|
||||
|
||||
#include "HC4067.h"
|
||||
|
||||
HC4067 mp(4, 5, 6, 7);
|
||||
HC4067 mp(4, 5, 6, 7); // no enable pin defined connect to GND.
|
||||
|
||||
const int inputPin = 10;
|
||||
uint16_t values;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -19,6 +19,7 @@ HC4067 mp(4, 5, 6, 7, 8);
|
||||
|
||||
uint32_t lastTime = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "HC4067.h"
|
||||
|
||||
HC4067 mp(4, 5, 6, 7);
|
||||
HC4067 mp(4, 5, 6, 7); // no enable pin defined connect to GND.
|
||||
|
||||
|
||||
void setup()
|
||||
@ -26,9 +26,11 @@ void loop()
|
||||
for (uint8_t channel = 0; channel < 16; channel++)
|
||||
{
|
||||
mp.setChannel(channel);
|
||||
Serial.println(analogRead(A0));
|
||||
Serial.print(analogRead(A0));
|
||||
Serial.print("\t");
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,10 +6,11 @@
|
||||
|
||||
#include "HC4067.h"
|
||||
|
||||
HC4067 mp(4, 5, 6, 7);
|
||||
HC4067 mp(4, 5, 6, 7, 8);
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -17,21 +18,30 @@ void setup()
|
||||
Serial.print("HC4067 LIBRARY VERSION: ");
|
||||
Serial.println(HC4067_LIB_VERSION);
|
||||
Serial.println();
|
||||
delay(100);
|
||||
|
||||
delay(1000);
|
||||
start = micros();
|
||||
mp.setChannel(10);
|
||||
stop = micros();
|
||||
|
||||
Serial.print("SetChannel: \t");
|
||||
Serial.println(stop - start);
|
||||
for (uint8_t ch = 0; ch < 16; ch ++)
|
||||
{
|
||||
start = micros();
|
||||
mp.setChannel(ch);
|
||||
stop = micros();
|
||||
Serial.print("Channel ");
|
||||
Serial.print(ch);
|
||||
Serial.print(": \t");
|
||||
Serial.println(stop - start);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
mp.setChannel(10);
|
||||
delay(100);
|
||||
|
||||
start = micros();
|
||||
mp.setChannel(10);
|
||||
stop = micros();
|
||||
|
||||
Serial.print("SetChannel: \t");
|
||||
Serial.print("\nSetChannel: \t");
|
||||
Serial.println(stop - start);
|
||||
delay(100);
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
|
||||
HC4067_performance.ino
|
||||
HC4067 LIBRARY VERSION: 0.2.0
|
||||
|
||||
Channel 0: 24
|
||||
Channel 1: 20
|
||||
Channel 2: 28
|
||||
Channel 3: 20
|
||||
Channel 4: 32
|
||||
Channel 5: 20
|
||||
Channel 6: 24
|
||||
Channel 7: 24
|
||||
Channel 8: 36
|
||||
Channel 9: 20
|
||||
Channel 10: 24
|
||||
Channel 11: 20
|
||||
Channel 12: 32
|
||||
Channel 13: 24
|
||||
Channel 14: 24
|
||||
Channel 15: 20
|
||||
|
||||
SetChannel: 8
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "HC4067.h"
|
||||
|
||||
HC4067 mp(4, 5, 6, 7, 8); // explicitly set enable pin
|
||||
HC4067 mp(4, 5, 6, 7, 8); // explicitly set enable pin (8)
|
||||
|
||||
|
||||
void setup()
|
||||
|
50
libraries/HC4067/examples/HC4067_write/HC4067_write.ino
Normal file
50
libraries/HC4067/examples/HC4067_write/HC4067_write.ino
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// FILE: HC4067_write.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for HC4067 16 channel (simple) multiplexer
|
||||
|
||||
|
||||
#include "HC4067.h"
|
||||
|
||||
HC4067 mp(4, 5, 6, 7, 3); // explicitly set enable pin (3)
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("HC4067 LIBRARY VERSION: ");
|
||||
Serial.println(HC4067_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
|
||||
pinMode(8, OUTPUT);
|
||||
digitalWrite(8, HIGH);
|
||||
|
||||
Serial.println(mp.isEnabled());
|
||||
mp.enable();
|
||||
Serial.println(mp.isEnabled());
|
||||
mp.disable();
|
||||
Serial.println(mp.isEnabled());
|
||||
mp.enable();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// rotate over the channels
|
||||
for (uint8_t channel = 0; channel < 16; channel++)
|
||||
{
|
||||
mp.setChannel(channel);
|
||||
Serial.println(channel);
|
||||
delay(250);
|
||||
}
|
||||
|
||||
// Toggle the OUTPUT
|
||||
digitalWrite(8, digitalRead(8));
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/HC4067.git"
|
||||
},
|
||||
"version": "0.1.2",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=HC4067
|
||||
version=0.1.2
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for a HC4067 1 x 16 channel multiplexer
|
||||
|
Loading…
Reference in New Issue
Block a user