Skip to content

Commit

Permalink
update setChannel() (#6)
Browse files Browse the repository at this point in the history
- change return type of **bool setChannel()**
- verify the channel parameter of **bool setChannel()**
- add parameter to **bool setChannel(channel, disable = true)**
- update readme.md
  • Loading branch information
RobTillaart authored May 28, 2024
1 parent b979afc commit edab20e
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.2.1] - 2024-05-28
- change return type of **bool setChannel()**
- verify the channel parameter of **bool setChannel()**
- add parameter to **bool setChannel(channel, disable = true)**
- update readme.md

## [0.2.0] - 2024-04-03
- fix ghost channels when using for OUTPUT
- add disable/enable in setChannel()
Expand Down
15 changes: 10 additions & 5 deletions HC4067.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// FILE: HC4067.h
// AUTHOR: Rob Tillaart
// DATE: 2023-01-25
// VERSION: 0.2.0
// VERSION: 0.2.1
// PURPOSE: Arduino library for CD74HC4067 1 x 16 channel multiplexer and compatibles.
// URL: https://github.com/RobTillaart/HC4067



#include "Arduino.h"

#define HC4067_LIB_VERSION (F("0.2.0"))
#define HC4067_LIB_VERSION (F("0.2.1"))


class HC4067
Expand Down Expand Up @@ -40,15 +40,19 @@ class HC4067
}


void setChannel(uint8_t channel)
bool setChannel(uint8_t channel, bool disable = true)
{
uint8_t _new = channel & 0x0F;
if (channel > 15) return false;
uint8_t _new = channel;
if (_new != _channel)
{
uint8_t _changed = _new ^ _channel;
uint8_t mask = 0x08;
uint8_t i = 3;
disable(); // prevent ghost channels.
if (disable)
{
this->disable(); // prevent ghost channels.
}
while (mask)
{
// only write changed pins. // AVR only?
Expand All @@ -61,6 +65,7 @@ class HC4067
enable();
_channel = _new;
}
return true;
}


Expand Down
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@ This will result in another subset of the Y pins to select from.
- **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.
- **bool setChannel(uint8_t channel, bool disable = true)** set the current channel.
Valid values 0..15, this value is checked (since 0.2.1).
Returns false if channel out of range.
If the channel is already selected it does not change it.
Note the four channels will not change at the very same moment,
possibly resulting in an invalid selection for a (very short) time.
The disable flag can be set to false so the device is not disabled during channel switching.
Default the device is disabled during channel switching to prevent (very short) ghost channels.
Note that a call to **setChannel()** will always enable the device again.
Note the device cannot be disabled if there is no enable pin configured.
- **uint8_t getChannel()** returns the current channel 0..15.
The selected channel is also returned when the multiplexer is disabled.

Expand All @@ -122,9 +130,9 @@ The selected channel is also returned when the multiplexer is disabled.

These functions work only if enablePin is set in the constructor.

- **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.
- **void enable()** enables the device to multiplex.
- **void disable()** disables the device, no channel is selected.
- **bool isEnabled()** returns the current status of the device.
Also returns true if the enablePin is not set in the constructor.


Expand All @@ -146,10 +154,10 @@ Also returns true if the enablePin is not set in the constructor.

#### Won't (unless requested)

- check channel in setChannel() ?
- return true if in range, false otherwise.
- move code to .cpp file

- uint8_t channelCount() { return 16; };
- cache enable status
- inline the enable/disable

## Support

Expand Down
1 change: 1 addition & 0 deletions examples/HC4067_16_buttons/HC4067_16_buttons.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for HC4067 16 channel (simple) multiplexer
// read 16 buttons / switches.
// URL: https://github.com/RobTillaart/HC4067


#include "HC4067.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FILE: HC4067_4_channel_plotter.ino
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for HC4067 16 channel (simple) multiplexer
//
// URL: https://github.com/RobTillaart/HC4067

// connect analog channel A0 to the multiplexer
// connect 4 analog signals to input 0..3 of the multiplexer
Expand Down
1 change: 1 addition & 0 deletions examples/HC4067_demo/HC4067_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// FILE: HC4067_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for HC4067 16 channel (simple) multiplexer
// URL: https://github.com/RobTillaart/HC4067


#include "HC4067.h"
Expand Down
3 changes: 2 additions & 1 deletion examples/HC4067_performance/HC4067_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// FILE: HC4067_performance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for HC4067 16 channel (simple) multiplexer
// URL: https://github.com/RobTillaart/HC4067


#include "HC4067.h"

HC4067 mp(4, 5, 6, 7, 8);
HC4067 mp(4, 5, 6, 7, 8); // enable pin(8)

uint32_t start, stop;

Expand Down
1 change: 1 addition & 0 deletions examples/HC4067_test/HC4067_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// FILE: HC4067_test.ino
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for HC4067 16 channel (simple) multiplexer
// URL: https://github.com/RobTillaart/HC4067


#include "HC4067.h"
Expand Down
1 change: 1 addition & 0 deletions examples/HC4067_write/HC4067_write.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// FILE: HC4067_write.ino
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for HC4067 16 channel (simple) multiplexer
// URL: https://github.com/RobTillaart/HC4067


#include "HC4067.h"
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ HC4067 KEYWORD1
# Methods and Functions (KEYWORD2)
setChannel KEYWORD2
getChannel KEYWORD2

enable KEYWORD2
disable KEYWORD2
isEnabled KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/HC4067.git"
},
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=HC4067
version=0.2.0
version=0.2.1
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for a HC4067 1 x 16 channel multiplexer
Expand Down

0 comments on commit edab20e

Please sign in to comment.