mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 HC4053
This commit is contained in:
parent
265fc6086b
commit
9d0c5e722c
28
libraries/HC4053/.arduino-ci.yml
Normal file
28
libraries/HC4053/.arduino-ci.yml
Normal file
@ -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
|
||||
|
4
libraries/HC4053/.github/FUNDING.yml
vendored
Normal file
4
libraries/HC4053/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
13
libraries/HC4053/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/HC4053/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -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
|
17
libraries/HC4053/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/HC4053/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -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
|
18
libraries/HC4053/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/HC4053/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -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$"
|
||||
|
11
libraries/HC4053/CHANGELOG.md
Normal file
11
libraries/HC4053/CHANGELOG.md
Normal file
@ -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
|
||||
|
139
libraries/HC4053/HC4053.h
Normal file
139
libraries/HC4053/HC4053.h
Normal file
@ -0,0 +1,139 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: HC4053.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2023-01-25
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for CD74HC4053 8 channel multiplexer and compatibles.
|
||||
// URL: https://github.com/RobTillaart/HC4053
|
||||
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define HC4053_LIB_VERSION (F("0.1.0"))
|
||||
|
||||
|
||||
class HC4053
|
||||
{
|
||||
public:
|
||||
explicit HC4053(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);
|
||||
}
|
||||
// two states only (could be one byte)
|
||||
_channelA = 0;
|
||||
_channelB = 0;
|
||||
_channelC = 0;
|
||||
|
||||
if (enablePin != 255)
|
||||
{
|
||||
_enablePin = enablePin;
|
||||
pinMode(_enablePin, OUTPUT);
|
||||
digitalWrite(_enablePin, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setChannel(uint8_t channel)
|
||||
{
|
||||
setChannelA(channel);
|
||||
setChannelB(channel);
|
||||
setChannelC(channel);
|
||||
}
|
||||
|
||||
|
||||
void setChannelA(uint8_t channel)
|
||||
{
|
||||
if (_channelA != (channel & 0x01))
|
||||
{
|
||||
_channelA = channel & 0x01;
|
||||
digitalWrite(_pins[0], _channelA);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setChannelB(uint8_t channel)
|
||||
{
|
||||
if (_channelB != (channel & 0x01))
|
||||
{
|
||||
_channelB = channel & 0x01;
|
||||
digitalWrite(_pins[1], _channelB);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setChannelC(uint8_t channel)
|
||||
{
|
||||
if (_channelC != (channel & 0x01))
|
||||
{
|
||||
_channelC = channel & 0x01;
|
||||
digitalWrite(_pins[2], _channelC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t getChannelA()
|
||||
{
|
||||
return _channelA;
|
||||
}
|
||||
|
||||
|
||||
uint8_t getChannelB()
|
||||
{
|
||||
return _channelB;
|
||||
}
|
||||
|
||||
|
||||
uint8_t getChannelC()
|
||||
{
|
||||
return _channelC;
|
||||
}
|
||||
|
||||
|
||||
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 _channelA = 0;
|
||||
uint8_t _channelB = 0;
|
||||
uint8_t _channelC = 0;
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/HC4053/LICENSE
Normal file
21
libraries/HC4053/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023-2023 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
114
libraries/HC4053/README.md
Normal file
114
libraries/HC4053/README.md
Normal file
@ -0,0 +1,114 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/HC4053/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/HC4053/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/HC4053/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/HC4053/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/HC4053/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/HC4053/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/HC4053.svg?maxAge=3600)](https://github.com/RobTillaart/HC4053/releases)
|
||||
|
||||
|
||||
# HC4053
|
||||
|
||||
HC4053 is an Arduino library for a HC4053 3x2 channel multiplexer.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
HC4053 is a library to control the CD74HC4053 3x2 channel
|
||||
multiplexer / demultiplexer and compatible devices.
|
||||
|
||||
The HC4053 is in fact three separate controllable switches in one,
|
||||
and every switch can be set indepently in one of two positions.
|
||||
This is functionaly different from both the 4051, 4052 and 4067
|
||||
in which there is only one channel selection
|
||||
|
||||
The independent channel selection is done with three 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
|
||||
- https://github.com/RobTillaart/HC4052
|
||||
- https://github.com/RobTillaart/HC4053
|
||||
- https://github.com/RobTillaart/HC4067
|
||||
|
||||
|
||||
## Hardware connection
|
||||
|
||||
Typical connection is to connect the three **select pins** to three 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 3x analog in.
|
||||
|
||||
```
|
||||
processor HC4053
|
||||
+-------------+ +-------------+
|
||||
| | | |
|
||||
| E |------------->| INH |
|
||||
| | | |
|
||||
| A |------------->| A X0 |
|
||||
| analog X |<-------------| X X1 |
|
||||
| | | |
|
||||
| B |------------->| B Y0 |
|
||||
| analog Y |<-------------| Y Y1 |
|
||||
| | | |
|
||||
| C |------------->| C Z0 |
|
||||
| analog Z |<-------------| Z Z1 |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| GND |--------------| GND |
|
||||
| | | VCC |
|
||||
| | | |
|
||||
+-------------+ +-------------+
|
||||
```
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "HC4053.h"
|
||||
```
|
||||
|
||||
#### Core
|
||||
|
||||
- **HC4053(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)** sets A, B and C to channel in one call.
|
||||
Think of it as a master switch.
|
||||
Valid values 0, 1, this value is not checked, only last bit is used.
|
||||
Note the channels will not change at the very same moment.
|
||||
- **void setChannelA(uint8_t channel)** sets A to channel.
|
||||
Valid values 0, 1, this value is not checked, only last bit is used.
|
||||
- **void setChannelB(uint8_t channel)** sets B to channel.
|
||||
Valid values 0, 1, this value is not checked, only last bit is used.
|
||||
- **void setChannelC(uint8_t channel)** sets C to channel.
|
||||
Valid values 0, 1, this value is not checked, only last bit is used.
|
||||
- **uint8_t getChannelA()** get current A channel 0 or 1.
|
||||
- **uint8_t getChannelB()** get current B channel 0 or 1.
|
||||
- **uint8_t getChannelC()** get current C channel 0 or 1.
|
||||
|
||||
|
||||
#### 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.
|
||||
|
55
libraries/HC4053/examples/HC4053_demo/HC4053_demo.ino
Normal file
55
libraries/HC4053/examples/HC4053_demo/HC4053_demo.ino
Normal file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// FILE: HC4053_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for HC4051 8 channel (simple) multiplexer
|
||||
|
||||
|
||||
#include "HC4053.h"
|
||||
|
||||
HC4053 mp(4, 5, 6);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("HC4053 LIBRARY VERSION: ");
|
||||
Serial.println(HC4053_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
mp.setChannelA(0);
|
||||
Serial.println(analogRead(A0));
|
||||
delay(100);
|
||||
|
||||
mp.setChannelB(0);
|
||||
Serial.println(analogRead(A1));
|
||||
delay(100);
|
||||
|
||||
mp.setChannelC(0);
|
||||
Serial.println(analogRead(A2));
|
||||
delay(100);
|
||||
|
||||
mp.setChannelA(1);
|
||||
Serial.println(analogRead(A0));
|
||||
delay(100);
|
||||
|
||||
mp.setChannelB(1);
|
||||
Serial.println(analogRead(A1));
|
||||
delay(100);
|
||||
|
||||
mp.setChannelC(1);
|
||||
Serial.println(analogRead(A2));
|
||||
delay(100);
|
||||
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
17
libraries/HC4053/keywords.txt
Normal file
17
libraries/HC4053/keywords.txt
Normal file
@ -0,0 +1,17 @@
|
||||
# Syntax Colouring Map For HC4053
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
HC4053 KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
setChannel KEYWORD2
|
||||
getChannel KEYWORD2
|
||||
enable KEYWORD2
|
||||
disable KEYWORD2
|
||||
isEnabled KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
HC4053_LIB_VERSION LITERAL1
|
||||
|
||||
|
23
libraries/HC4053/library.json
Normal file
23
libraries/HC4053/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "HC4053",
|
||||
"keywords": "",
|
||||
"description": "Arduino library for a HC4053 3x2 channel multiplexer.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/HC4053.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"headers": "HC4053.h"
|
||||
}
|
11
libraries/HC4053/library.properties
Normal file
11
libraries/HC4053/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=HC4053
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for a HC4053 3x2 channel multiplexer
|
||||
paragraph=
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/HC4053
|
||||
architectures=*
|
||||
includes=HC4053.h
|
||||
depends=
|
79
libraries/HC4053/test/unit_test_001.cpp
Normal file
79
libraries/HC4053/test/unit_test_001.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2023-01-25
|
||||
// PURPOSE: unit tests for the HC4053 sensor
|
||||
// https://github.com/RobTillaart/HC4067
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual)
|
||||
// assertNotEqual(expected, actual)
|
||||
// assertLess(expected, actual)
|
||||
// assertMore(expected, actual)
|
||||
// assertLessOrEqual(expected, actual)
|
||||
// assertMoreOrEqual(expected, actual)
|
||||
// assertTrue(actual)
|
||||
// assertFalse(actual)
|
||||
// assertNull(actual)
|
||||
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "HC4053.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "HC4053_LIB_VERSION: %s\n", (char *) HC4053_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_channel)
|
||||
{
|
||||
HC4053 mp(3,4,5);
|
||||
|
||||
mp.setChannelA(0);
|
||||
assertEqual(0, mp.getChannelA());
|
||||
mp.setChannelA(1);
|
||||
assertEqual(1, mp.getChannelA());
|
||||
|
||||
mp.setChannelB(0);
|
||||
assertEqual(0, mp.getChannelB());
|
||||
mp.setChannelB(1);
|
||||
assertEqual(1, mp.getChannelB());
|
||||
|
||||
mp.setChannelC(0);
|
||||
assertEqual(0, mp.getChannelC());
|
||||
mp.setChannelC(1);
|
||||
assertEqual(1, mp.getChannelC());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_enable)
|
||||
{
|
||||
HC4053 mp1(3,4,5);
|
||||
assertTrue(mp1.isEnabled());
|
||||
|
||||
HC4053 mp2(3,4,5,6);
|
||||
assertFalse(mp2.isEnabled());
|
||||
|
||||
mp2.enable();
|
||||
assertTrue(mp2.isEnabled());
|
||||
|
||||
mp2.disable();
|
||||
assertFalse(mp2.isEnabled());
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
Loading…
Reference in New Issue
Block a user