0.1.0 74HC138

This commit is contained in:
Rob Tillaart 2024-02-23 14:27:13 +01:00
parent 33c0825f15
commit 94ba9785d6
16 changed files with 599 additions and 0 deletions

View 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/74HC138/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View 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

View 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

View 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$"

128
libraries/74HC138/74HC138.h Normal file
View File

@ -0,0 +1,128 @@
#pragma once
//
// FILE: 74HC138.h
// AUTHOR: Rob Tillaart
// DATE: 2024-02-22
// VERSION: 0.1.0
// PURPOSE: Arduino library for the 74HC138 3-to-8 line decoder/demultiplexer.
// URL: https://github.com/RobTillaart/74HC138
#include "Arduino.h"
#define LIB_74HC138_VERSION (F("0.1.0"))
class DEV_74HC138
{
public:
DEV_74HC138(uint8_t pin0, uint8_t pin1, uint8_t pin2, uint8_t pinEnable = 255)
{
_pin[0] = pin0;
_pin[1] = pin1;
_pin[2] = pin2;
_enable = pinEnable;
_line = 0;
for (int i = 0; i < 3; i++)
{
pinMode(_pin[i], OUTPUT);
digitalWrite(_pin[i], LOW);
}
if (pinEnable != 255)
{
// default disable.
pinMode(_enable, OUTPUT);
digitalWrite(_enable, HIGH);
}
}
DEV_74HC138(uint8_t * pins, uint8_t pinEnable = 255)
{
_line = 0;
for (int i = 0; i < 3; 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..7
bool setLine(uint8_t nr)
{
if (nr > 7) return false;
_line = nr;
_setLine();
return true;
}
uint8_t getLine()
{
return _line;
}
void nextLine()
{
if (_line >= 7) _line = 0;
else _line++;
_setLine();
}
void prevLine()
{
if (_line == 0) _line = 7;
else _line--;
_setLine();
}
void enable()
{
digitalWrite(_enable, LOW);
}
void disable()
{
digitalWrite(_enable, HIGH);
}
bool isEnabled()
{
return digitalRead(_enable);
}
private:
uint8_t _pin[3];
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);
}
/*
uint8_t getLine()
{
uint8_t val = digitalRead(_pin[0]);
val |= digitalRead(_pin[1]) << 1;
val |= digitalRead(_pin[2]) << 2;
return val;
};
*/
};
// -- END OF FILE --

View File

@ -0,0 +1,13 @@
# Change Log DEV_74HC138
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-22
- initial version

21
libraries/74HC138/LICENSE Normal file
View 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.

View File

@ -0,0 +1,90 @@
[![Arduino CI](https://github.com/RobTillaart/74HC138/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/74HC138/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/74HC138/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/74HC138/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/74HC138/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/74HC138.svg)](https://github.com/RobTillaart/74HC138/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/74HC138/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/74HC138.svg?maxAge=3600)](https://github.com/RobTillaart/74HC138/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/74HC138.svg)](https://registry.platformio.org/libraries/robtillaart/74HC138)
# 74HC138
Arduino library for the 74HC138 3-to-8 line decoder/demultiplexer.
## Description
This library controls the 74HC138 3 to 8 line decoder.
With 3 IO lines one can select one of 8 output lines.
#### Related
- 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 "74HC138.h"
```
#### Constructor
- **74HC138(uint8_t pin0, uint8_t pin1, uint8_t pin2, uint8_t pinEnable = 255)**
set the 3 selection IO lines from pin numbers.
Optionally set the enable pin, connect to E1 or E2, see datasheet.
- **74HC138(uint8_t \* pins, uint8_t pinEnable = 255)**
set the 3 selection IO lines from an array.
The pins array should have at least 3 elements.
Optionally set the enable pin, connect to E1 or E2, see datasheet.
#### Select line
- **bool setLine(uint8_t line)** set line 0 .. 7. Returns false if out of range.
- **uint8_t getLine()** returns 0 .. 7
- **void nextLine()** selects the next line, wraps back to 0 is needed.
- **void prevLine()** selects the previous line, wraps to 7 is 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,

View File

@ -0,0 +1,38 @@
//
// FILE: 74HC138_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test basic behaviour and performance
// URL: https://github.com/RobTillaart/74HC138
#include "74HC138.h"
DEV_74HC138 selector(5, 6, 7);
uint8_t line = 0;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("LIB_74HC138_VERSION: ");
Serial.println(LIB_74HC138_VERSION);
selector.enable();
}
void loop()
{
Serial.println(selector.getLine());
delay(100);
selector.setLine(line);
line++;
if (line >= 8) line = 0;
delay(1000);
}
// -- END OF FILE --

View File

@ -0,0 +1,45 @@
//
// FILE: 74HC138_night_rider.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test basic behaviour and performance
// URL: https://github.com/RobTillaart/
#include "74HC138.h"
DEV_74HC138 selector(5, 6, 7);
uint8_t line = 0;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("LIB_74HC138_VERSION: ");
Serial.println(LIB_74HC138_VERSION);
selector.enable();
}
void loop()
{
for (int i = 0; i < 8; i++)
{
Serial.println(selector.getLine());
selector.nextLine();
delay(100);
}
for (int i = 0; i < 8; i++)
{
Serial.println(selector.getLine());
selector.prevLine();
delay(100);
}
}
// -- END OF FILE --

View File

@ -0,0 +1,45 @@
//
// FILE: 74HC138_prev_next.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test basic behaviour and performance
// URL: https://github.com/RobTillaart/74HC138
#include "74HC138.h"
DEV_74HC138 selector(5, 6, 7);
uint8_t line = 0;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("LIB_74HC138_VERSION: ");
Serial.println(LIB_74HC138_VERSION);
selector.enable();
}
void loop()
{
for (int i = 0; i < 20; i++)
{
Serial.println(selector.getLine());
selector.nextLine();
delay(100);
}
for (int i = 0; i < 20; i++)
{
Serial.println(selector.getLine());
selector.prevLine();
delay(100);
}
}
// -- END OF FILE --

View File

@ -0,0 +1,20 @@
# Syntax Colouring Map For DEV_74HC138
# Data types (KEYWORD1)
DEV_74HC138 KEYWORD1
# Methods and Functions (KEYWORD2)
setLine KEYWORD2
getLine KEYWORD2
nextLine KEYWORD2
prevLine KEYWORD2
enable KEYWORD2
disable KEYWORD2
isEnabled KEYWORD2
# Constants (LITERAL1)
LIB_74HC138_VERSION LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "74HC138",
"keywords": "3 to 8",
"description": "Arduino library for the 74HC138 3-to-8 line decoder/demultiplexer.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/74HC138.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
"headers": "74HC138.h"
}

View File

@ -0,0 +1,11 @@
name=74HC138
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the 74HC138 3-to-8 line decoder/demultiplexer.
paragraph=
category=Sensors
url=https://github.com/RobTillaart/74HC138
architectures=*
includes=74HC138.h
depends=

View File

@ -0,0 +1,83 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2024-02-22
// PURPOSE: unit tests for the ACD10 library
// URL: https://github.com/RobTillaart/74HC138
//
// 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 "74HC138.h"
unittest_setup()
{
fprintf(stderr, "LIB_74HC138_VERSION: %s\n", (char *) LIB_74HC138_VERSION);
}
unittest_teardown()
{
}
unittest(test_setLine)
{
DEV_74HC138 dev(5, 6, 7);
for (int i = 0; i < 8; i++)
{
assertTrue(dev.setLine(i));
assertEqual(i, dev.getLine());
}
assertFalse(dev.setLine(8));
}
unittest(test_nextLine)
{
DEV_74HC138 dev(5, 6, 7);
assertTrue(dev.setLine(0));
for (int i = 0; i < 8; i++)
{
assertEqual(i, dev.getLine());
dev.nextLine();
}
}
unittest(test_prevLine)
{
DEV_74HC138 dev(5, 6, 7);
assertTrue(dev.setLine(7));
for (int i = 7; i > 0; i--)
{
assertEqual(i, dev.getLine());
dev.prevLine();
}
}
unittest_main()
// -- END OF FILE --