-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from RobTillaart/develop
initial release
- Loading branch information
Showing
14 changed files
with
442 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
platforms: | ||
rpipico: | ||
board: rp2040:rp2040:rpipico | ||
package: rp2040:rp2040 | ||
gcc: | ||
features: | ||
defines: | ||
- ARDUINO_ARCH_RP2040 | ||
warnings: | ||
flags: | ||
|
||
packages: | ||
rp2040:rp2040: | ||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json | ||
|
||
compile: | ||
# Choosing to run compilation tests on 2 different Arduino platforms | ||
platforms: | ||
- uno | ||
# - due | ||
# - zero | ||
# - leonardo | ||
- m4 | ||
- esp32 | ||
- esp8266 | ||
# - mega2560 | ||
- rpipico | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# These are supported funding model platforms | ||
|
||
github: RobTillaart | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
name: Arduino-lint | ||
|
||
on: [push, pull_request] | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: arduino/arduino-lint-action@v1 | ||
with: | ||
library-manager: update | ||
compliance: strict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Arduino CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
runTest: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 2.6 | ||
- run: | | ||
gem install arduino_ci | ||
arduino_ci.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: JSON check | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.json' | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: json-syntax-check | ||
uses: limitusus/json-syntax-check@v1 | ||
with: | ||
pattern: "\\.json$" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Change Log HC4051 | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
|
||
## [0.1.0] - 2023-01-25 | ||
- initial version | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#pragma once | ||
// | ||
// FILE: HC4051.h | ||
// AUTHOR: Rob Tillaart | ||
// DATE: 2023-01-25 | ||
// VERSION: 0.1.0 | ||
// PURPOSE: Arduino library for CD74HC4051 8 channel multiplexer and compatibles. | ||
// URL: https://github.com/RobTillaart/HC4051 | ||
|
||
|
||
|
||
#include "Arduino.h" | ||
|
||
#define HC4051_LIB_VERSION (F("0.1.0")) | ||
|
||
|
||
class HC4051 | ||
{ | ||
public: | ||
explicit HC4051(uint8_t A, uint8_t B, uint8_t C, uint8_t enablePin = 255) | ||
{ | ||
_pins[0] = A; | ||
_pins[1] = B; | ||
_pins[2] = C; | ||
uint8_t i = 3; | ||
while (i--) | ||
{ | ||
pinMode(_pins[i], OUTPUT); | ||
digitalWrite(_pins[i], LOW); | ||
} | ||
_channel = 0; | ||
|
||
if (enablePin != 255) | ||
{ | ||
_enablePin = enablePin; | ||
pinMode(_enablePin, OUTPUT); | ||
digitalWrite(_enablePin, HIGH); | ||
} | ||
} | ||
|
||
|
||
void setChannel(uint8_t channel) | ||
{ | ||
if ((channel & 0x07) != _channel) | ||
{ | ||
_channel = channel & 0x07; | ||
digitalWrite(_pins[0], _channel & 0x01); | ||
digitalWrite(_pins[1], _channel & 0x02); | ||
digitalWrite(_pins[2], _channel & 0x04); | ||
} | ||
} | ||
|
||
|
||
uint8_t getChannel() | ||
{ | ||
return _channel; | ||
} | ||
|
||
|
||
void enable() | ||
{ | ||
if (_enablePin != 255) | ||
{ | ||
digitalWrite(_enablePin, LOW); | ||
} | ||
} | ||
|
||
|
||
void disable() | ||
{ | ||
if (_enablePin != 255) | ||
{ | ||
digitalWrite(_enablePin, HIGH); | ||
} | ||
} | ||
|
||
|
||
bool isEnabled() | ||
{ | ||
if (_enablePin != 255) | ||
{ | ||
return (digitalRead(_enablePin) == LOW); | ||
} | ||
return true; | ||
} | ||
|
||
|
||
private: | ||
uint8_t _pins[3]; | ||
uint8_t _enablePin = 255; | ||
uint8_t _channel = 0; | ||
}; | ||
|
||
|
||
// -- END OF FILE -- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,98 @@ | ||
|
||
[![Arduino CI](https://github.com/RobTillaart/HC4051/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) | ||
[![Arduino-lint](https://github.com/RobTillaart/HC4051/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/HC4051/actions/workflows/arduino-lint.yml) | ||
[![JSON check](https://github.com/RobTillaart/HC4051/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/HC4051/actions/workflows/jsoncheck.yml) | ||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/HC4051/blob/master/LICENSE) | ||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/HC4051.svg?maxAge=3600)](https://github.com/RobTillaart/HC4051/releases) | ||
|
||
|
||
# HC4051 | ||
Arduino library for CD74HC4051 1x8 channel multiplexer and compatibles. | ||
|
||
HC4051 is an Arduino library for a HC4051 1x8 channel multiplexer. | ||
|
||
|
||
## Description | ||
|
||
HC4051 is a library to control the CD74HC4051 8 channel | ||
multiplexer / demultiplexer and compatible devices. | ||
|
||
The HC4051 allows e.g one analog port read up to 8 different analog channels, | ||
or one digital port to read the state of 8 buttons. | ||
|
||
|
||
The channel selection is done with four select lines **A, B, C** | ||
|
||
The device can be enabled/disabled by the enable line **INH** | ||
|
||
|
||
#### Compatibles | ||
|
||
to elaborate. | ||
|
||
|
||
#### Related to | ||
|
||
- https://github.com/RobTillaart/HC4051 (1x8 mux) | ||
- https://github.com/RobTillaart/HC4052 (2x8 mux) | ||
- https://github.com/RobTillaart/HC4053 (3x2 mux) | ||
- https://github.com/RobTillaart/HC4067 (1x16 mux) | ||
|
||
|
||
## Hardware connection | ||
|
||
Typical connection is to connect the four **select pins** to four IO Pins of your board. | ||
|
||
The optional **enablePin (INH)** must be connected to GND if not used. | ||
This way the device is continuous enabled. | ||
|
||
Example multiplexing analog in. | ||
|
||
``` | ||
processor HC4051 | ||
+-------------+ +-------------+ | ||
| | | | | ||
| A |------------->| S0 Y0 | | ||
| B |------------->| S1 Y1 | | ||
| C |------------->| S2 Y2 | | ||
| | | Y3 | | ||
| E |------------->| INH Y4 | | ||
| | | Y5 | | ||
| A0 |<-------------| Y Y6 | | ||
| | | Y7 | | ||
| GND |--------------| GND Y8 | | ||
| | | VCC | | ||
| | | | | ||
+-------------+ +-------------+ | ||
``` | ||
|
||
|
||
## Interface | ||
|
||
```cpp | ||
#include "HC4051.h" | ||
``` | ||
|
||
#### Core | ||
|
||
- **HC4051(uint8_t A, uint8_t B, uint8_t C, uint8_t enablePin = 255)** constructor. | ||
Set the three 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..7, this value is not checked, only the lower 3 bits will be used. | ||
- **uint8_t getChannel()** get current channel 0..7. | ||
|
||
|
||
#### 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. | ||
|
||
|
||
## Future | ||
|
||
- keep in sync with HC4067 et.al. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// FILE: HC4051_demo.ino | ||
// AUTHOR: Rob Tillaart | ||
// PURPOSE: Demo for HC4051 8 channel (simple) multiplexer | ||
|
||
|
||
#include "HC4051.h" | ||
|
||
HC4051 mp(4, 5, 6); | ||
|
||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(__FILE__); | ||
Serial.print("HC4051 LIBRARY VERSION: "); | ||
Serial.println(HC4051_LIB_VERSION); | ||
Serial.println(); | ||
|
||
delay(1000); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
for (uint8_t channel = 0; channel < 8; channel++) | ||
{ | ||
mp.setChannel(channel); | ||
Serial.println(analogRead(A0)); | ||
delay(100); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Syntax Colouring Map For HC4051 | ||
|
||
# Data types (KEYWORD1) | ||
HC4051 KEYWORD1 | ||
|
||
# Methods and Functions (KEYWORD2) | ||
setChannel KEYWORD2 | ||
getChannel KEYWORD2 | ||
enable KEYWORD2 | ||
disable KEYWORD2 | ||
isEnabled KEYWORD2 | ||
|
||
|
||
# Constants (LITERAL1) | ||
HC4051_LIB_VERSION LITERAL1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "HC4051", | ||
"keywords": "", | ||
"description": "Arduino library for a HC4051 1x8 channel multiplexer.", | ||
"authors": | ||
[ | ||
{ | ||
"name": "Rob Tillaart", | ||
"email": "Rob.Tillaart@gmail.com", | ||
"maintainer": true | ||
} | ||
], | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/RobTillaart/HC4051.git" | ||
}, | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"frameworks": "arduino", | ||
"platforms": "*", | ||
"headers": "HC4051.h" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name=HC4051 | ||
version=0.1.0 | ||
author=Rob Tillaart <rob.tillaart@gmail.com> | ||
maintainer=Rob Tillaart <rob.tillaart@gmail.com> | ||
sentence=Arduino library for a HC4051 1x8 channel multiplexer | ||
paragraph= | ||
category=Sensors | ||
url=https://github.com/RobTillaart/HC4051 | ||
architectures=* | ||
includes=HC4051.h | ||
depends= |
Oops, something went wrong.