mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 74HC154
This commit is contained in:
parent
94ba9785d6
commit
5bd103d2dd
30
libraries/74HC154/.arduino-ci.yml
Normal file
30
libraries/74HC154/.arduino-ci.yml
Normal file
@ -0,0 +1,30 @@
|
||||
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
|
||||
|
||||
libraries:
|
||||
- "printHelpers"
|
4
libraries/74HC154/.github/FUNDING.yml
vendored
Normal file
4
libraries/74HC154/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
13
libraries/74HC154/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/74HC154/.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/74HC154/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/74HC154/.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/74HC154/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/74HC154/.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$"
|
||||
|
131
libraries/74HC154/74HC154.h
Normal file
131
libraries/74HC154/74HC154.h
Normal file
@ -0,0 +1,131 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: 74HC154.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2024-02-22
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for the 74HC154 4-to-16 line decoder/demultiplexer.
|
||||
// URL: https://github.com/RobTillaart/74HC154
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define LIB_74HC154_VERSION (F("0.1.0"))
|
||||
|
||||
|
||||
|
||||
class DEV_74HC154
|
||||
{
|
||||
public:
|
||||
DEV_74HC154(uint8_t pin0, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pinEnable = 255)
|
||||
{
|
||||
_pin[0] = pin0;
|
||||
_pin[1] = pin1;
|
||||
_pin[2] = pin2;
|
||||
_pin[3] = pin3;
|
||||
_enable = pinEnable;
|
||||
_line = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
pinMode(_pin[i], OUTPUT);
|
||||
digitalWrite(_pin[i], LOW);
|
||||
}
|
||||
if (pinEnable != 255)
|
||||
{
|
||||
// default disable.
|
||||
pinMode(_enable, OUTPUT);
|
||||
digitalWrite(_enable, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
DEV_74HC154(uint8_t * pins, uint8_t pinEnable = 255)
|
||||
{
|
||||
_line = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
_pin[i] = pins[i];
|
||||
pinMode(_pin[i], OUTPUT);
|
||||
digitalWrite(_pin[i], LOW);
|
||||
}
|
||||
if (pinEnable != 255)
|
||||
{
|
||||
// default disable.
|
||||
pinMode(_enable, OUTPUT);
|
||||
digitalWrite(_enable, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
// nr == 0..15
|
||||
bool setLine(uint8_t nr)
|
||||
{
|
||||
if (nr > 15) return false;
|
||||
_line = nr;
|
||||
_setLine();
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t getLine()
|
||||
{
|
||||
return _line;
|
||||
}
|
||||
|
||||
void nextLine()
|
||||
{
|
||||
if (_line >= 15) _line = 0;
|
||||
else _line++;
|
||||
_setLine();
|
||||
}
|
||||
|
||||
void prevLine()
|
||||
{
|
||||
if (_line == 0) _line = 15;
|
||||
else _line--;
|
||||
_setLine();
|
||||
}
|
||||
|
||||
void enable()
|
||||
{
|
||||
digitalWrite(_enable, LOW);
|
||||
}
|
||||
|
||||
void disable()
|
||||
{
|
||||
digitalWrite(_enable, HIGH);
|
||||
}
|
||||
|
||||
bool isEnabled()
|
||||
{
|
||||
return digitalRead(_enable);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
uint8_t _pin[4];
|
||||
uint8_t _enable = 255;
|
||||
uint8_t _line = 0;
|
||||
|
||||
void _setLine()
|
||||
{
|
||||
digitalWrite(_pin[0], _line & 0x01);
|
||||
digitalWrite(_pin[1], _line & 0x02);
|
||||
digitalWrite(_pin[2], _line & 0x04);
|
||||
digitalWrite(_pin[3], _line & 0x08);
|
||||
}
|
||||
|
||||
/*
|
||||
uint8_t getLine()
|
||||
{
|
||||
uint8_t value = digitalRead(_pin[0]);
|
||||
value |= digitalRead(_pin[1]) << 1;
|
||||
value |= digitalRead(_pin[2]) << 2;
|
||||
value |= digitalRead(_pin[3]) << 4;
|
||||
return value;
|
||||
};
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
13
libraries/74HC154/CHANGELOG.md
Normal file
13
libraries/74HC154/CHANGELOG.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Change Log DEV_74HC154
|
||||
|
||||
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] - 2024-02-23
|
||||
- initial version
|
||||
|
||||
|
||||
|
21
libraries/74HC154/LICENSE
Normal file
21
libraries/74HC154/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024-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
|
||||
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.
|
91
libraries/74HC154/README.md
Normal file
91
libraries/74HC154/README.md
Normal file
@ -0,0 +1,91 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/74HC154/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/74HC154/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/74HC154/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/74HC154/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/74HC154/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/74HC154.svg)](https://github.com/RobTillaart/74HC154/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/74HC154/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/74HC154.svg?maxAge=3600)](https://github.com/RobTillaart/74HC154/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/74HC154.svg)](https://registry.platformio.org/libraries/robtillaart/74HC154)
|
||||
|
||||
|
||||
# 74HC154
|
||||
|
||||
Arduino library for the 74HC154 4-to-16 line decoder/demultiplexer.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
This library controls the 74HC154 4 to 6 line decoder.
|
||||
With 4 IO lines one can select one of 16 output lines.
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/74HC138 (3 to 8 selector)
|
||||
- https://github.com/RobTillaart/74HC154 (4 to 16 selector)
|
||||
- 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)
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "74HC154.h"
|
||||
```
|
||||
|
||||
#### Constructor
|
||||
|
||||
- **74HC154(uint8_t pin0, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pinEnable = 255)**
|
||||
set the 4 selection IO lines from pin numbers.
|
||||
Optionally set the enable pin, connect to E1 or E2, see datasheet.
|
||||
- **74HC154(uint8_t \* pins, uint8_t pinEnable = 255)**
|
||||
set the 4 selection IO lines from an array.
|
||||
The pins array should have at least 4 elements.
|
||||
Optionally set the enable pin, connect to E1, see datasheet.
|
||||
|
||||
|
||||
#### Select line
|
||||
|
||||
- **bool setLine(uint8_t line)** set line 0 .. 15. Returns false if out of range.
|
||||
- **uint8_t getLine()** returns 0 .. 15
|
||||
- **void nextLine()** selects the next line, wraps back to 0 if needed.
|
||||
- **void prevLine()** selects the previous line, wraps to 15 if needed.
|
||||
|
||||
|
||||
#### Enable
|
||||
|
||||
Works only if enable line is set in constructor.
|
||||
|
||||
- **void enable()** enables output / selection.
|
||||
- **void disable()** disables output / selection.
|
||||
- **bool isEnabled()** checks if line is enabled.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
- improve documentation
|
||||
- get hardware to test
|
||||
|
||||
#### Should
|
||||
|
||||
|
||||
#### Could
|
||||
|
||||
|
||||
#### Wont
|
||||
|
||||
|
||||
## 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,
|
||||
|
||||
|
38
libraries/74HC154/examples/74HC154_demo/74HC154_demo.ino
Normal file
38
libraries/74HC154/examples/74HC154_demo/74HC154_demo.ino
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// FILE: 74HC154_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: test basic behaviour and performance
|
||||
// URL: https://github.com/RobTillaart/
|
||||
|
||||
|
||||
#include "74HC154.h"
|
||||
|
||||
|
||||
DEV_74HC154 selector(5, 6, 7, 8);
|
||||
|
||||
uint8_t line = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("LIB_74HC154_VERSION: ");
|
||||
Serial.println(LIB_74HC154_VERSION);
|
||||
|
||||
selector.enable();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(selector.getLine());
|
||||
delay(100);
|
||||
selector.setLine(line);
|
||||
line++;
|
||||
if (line >= 16) line = 0;
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,45 @@
|
||||
//
|
||||
// FILE: 74HC154_night_rider.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: test basic behaviour and performance
|
||||
// URL: https://github.com/RobTillaart/
|
||||
|
||||
|
||||
#include "74HC154.h"
|
||||
|
||||
|
||||
DEV_74HC154 selector(5, 6, 7, 8);
|
||||
|
||||
uint8_t line = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("LIB_74HC154_VERSION: ");
|
||||
Serial.println(LIB_74HC154_VERSION);
|
||||
|
||||
selector.enable();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Serial.println(selector.getLine());
|
||||
selector.nextLine();
|
||||
delay(100);
|
||||
}
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Serial.println(selector.getLine());
|
||||
selector.prevLine();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,45 @@
|
||||
//
|
||||
// FILE: 74HC154_prev_next.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: test basic behaviour and performance
|
||||
// URL: https://github.com/RobTillaart/74HC154
|
||||
|
||||
|
||||
#include "74HC154.h"
|
||||
|
||||
|
||||
DEV_74HC154 selector(5, 6, 7, 8);
|
||||
|
||||
uint8_t line = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("LIB_74HC154_VERSION: ");
|
||||
Serial.println(LIB_74HC154_VERSION);
|
||||
|
||||
selector.enable();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Serial.println(selector.getLine());
|
||||
selector.nextLine();
|
||||
delay(100);
|
||||
}
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Serial.println(selector.getLine());
|
||||
selector.prevLine();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
20
libraries/74HC154/keywords.txt
Normal file
20
libraries/74HC154/keywords.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# Syntax Colouring Map For DEV_74HC154
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
DEV_74HC154 KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
setLine KEYWORD2
|
||||
getLine KEYWORD2
|
||||
nextLine KEYWORD2
|
||||
prevLine KEYWORD2
|
||||
|
||||
enable KEYWORD2
|
||||
disable KEYWORD2
|
||||
isEnabled KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
LIB_74HC154_VERSION LITERAL1
|
||||
|
23
libraries/74HC154/library.json
Normal file
23
libraries/74HC154/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "74HC154",
|
||||
"keywords": "3 to 8",
|
||||
"description": "Arduino library for the 74HC154 4-to-16 line decoder/demultiplexer.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/74HC154.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "74HC154.h"
|
||||
}
|
11
libraries/74HC154/library.properties
Normal file
11
libraries/74HC154/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=74HC154
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for the 74HC154 4 to 16 line decoder/demultiplexer.
|
||||
paragraph=
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/74HC154
|
||||
architectures=*
|
||||
includes=74HC154.h
|
||||
depends=
|
83
libraries/74HC154/test/unit_test_001.cpp
Normal file
83
libraries/74HC154/test/unit_test_001.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2024-02-23
|
||||
// PURPOSE: unit tests for the 74HC154 library
|
||||
// URL: https://github.com/RobTillaart/74HC154
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual)
|
||||
// assertNotEqual(expected, actual)
|
||||
// assertLess(expected, actual)
|
||||
// assertMore(expected, actual)
|
||||
// assertLessOrEqual(expected, actual)
|
||||
// assertMoreOrEqual(expected, actual)
|
||||
// assertTrue(actual)
|
||||
// assertFalse(actual)
|
||||
// assertNull(actual)
|
||||
// assertNotNull(actual)
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
|
||||
#include "74HC154.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "LIB_74HC154_VERSION: %s\n", (char *) LIB_74HC154_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_setLine)
|
||||
{
|
||||
DEV_74HC154 dev(5, 6, 7, 8);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
assertTrue(dev.setLine(i));
|
||||
assertEqual(i, dev.getLine());
|
||||
}
|
||||
assertFalse(dev.setLine(16));
|
||||
}
|
||||
|
||||
|
||||
unittest(test_nextLine)
|
||||
{
|
||||
DEV_74HC154 dev(5, 6, 7, 8);
|
||||
|
||||
assertTrue(dev.setLine(0));
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
assertEqual(i, dev.getLine());
|
||||
dev.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unittest(test_prevLine)
|
||||
{
|
||||
DEV_74HC154 dev(5, 6, 7, 8);
|
||||
|
||||
assertTrue(dev.setLine(15));
|
||||
for (int i = 15; i > 0; i--)
|
||||
{
|
||||
assertEqual(i, dev.getLine());
|
||||
dev.prevLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
Loading…
Reference in New Issue
Block a user