From 9127f3cde294358905980e6557802abf66527212 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Fri, 5 Jun 2026 16:42:07 +0200 Subject: [PATCH 1/2] add setInvert() + getInvert() --- .github/workflows/arduino-lint.yml | 2 +- .github/workflows/arduino_test_runner.yml | 3 +- .github/workflows/jsoncheck.yml | 2 +- CHANGELOG.md | 5 +++ LICENSE | 2 +- README.md | 34 ++++++++++++++++----- ShiftOutSlow.cpp | 22 +++++++++++-- ShiftOutSlow.h | 10 ++++-- examples/shiftOutSlow_demo/output_0.1.7.txt | 3 ++ keywords.txt | 3 ++ library.json | 2 +- library.properties | 2 +- 12 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 examples/shiftOutSlow_demo/output_0.1.7.txt diff --git a/.github/workflows/arduino-lint.yml b/.github/workflows/arduino-lint.yml index 0ad60f4..aed264b 100644 --- a/.github/workflows/arduino-lint.yml +++ b/.github/workflows/arduino-lint.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - uses: arduino/arduino-lint-action@v2 with: library-manager: update diff --git a/.github/workflows/arduino_test_runner.yml b/.github/workflows/arduino_test_runner.yml index 1897982..a2a5f07 100644 --- a/.github/workflows/arduino_test_runner.yml +++ b/.github/workflows/arduino_test_runner.yml @@ -6,9 +6,8 @@ jobs: runTest: runs-on: ubuntu-latest timeout-minutes: 20 - steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/.github/workflows/jsoncheck.yml b/.github/workflows/jsoncheck.yml index 8804e69..2c52dc7 100644 --- a/.github/workflows/jsoncheck.yml +++ b/.github/workflows/jsoncheck.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: json-syntax-check uses: limitusus/json-syntax-check@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c3dc1..fe3b28e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.7] - 2026-06-05 +- add setInvert(bool) and getInvert() +- update GitHub actions +- minor edits + ## [0.1.6] - 2025-09-12 - update GitHub actions - minor edits diff --git a/LICENSE b/LICENSE index 6e5129e..9a9c570 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021-2025 Rob Tillaart +Copyright (c) 2021-2026 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 diff --git a/README.md b/README.md index 6a4a3de..7024c70 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,17 @@ Arduino library for shiftOut with build-in delay - e.g. for 74HC595 **Experimental** -ShiftOutSlow is an experimental library that has a build in delay (in microseconds) that allows tuning the time per bit. +ShiftOutSlow is an experimental library that has a build in delay +(in microseconds) that allows tuning the time per bit. This allows one to improve reliability e.g. when using longer lines. -The data pin and clock pin are set in the constructor, the delay can be set per byte send to be able to optimize runtime. +The data pin and clock pin are set in the constructor, the delay +can be set per byte send to be able to optimize runtime. ShiftOutSlow implements the print interface. +Feedback as always is welcome. + #### Related @@ -37,11 +41,11 @@ ShiftOutSlow implements the print interface. ## Performance -The performance of **write()** with a delay of 0 microseconds is slower than the default Arduino -**shiftOut()** due to some overhead. +The performance of **write()** with a delay of 0 microseconds is slower +than the default Arduino **shiftOut()** due to some overhead. -The delay requested is divided by two to minimize disruption of the duty cycle of the clock pulse, -resulting in "better" pulses. +The delay requested is divided by two to minimize disruption of the +duty cycle of the clock pulse, resulting in "better" pulses. Performance measurements are meaningless, as the purpose of this library is to slow the pulse train to a working level. @@ -57,7 +61,7 @@ slow the pulse train to a working level. - **ShiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** constructor. -### Functions +### Write The interface exists of the following functions: @@ -67,15 +71,31 @@ Returns the bytes written. Uses **write(uint8_t)** so expect about equal performance. Returns the bytes written. - **uint8_t lastWritten()** returns last value written. + +### Delay + - **void setDelay(uint16_t microSeconds = 0)** set delay per **bit** from 0 .. 65535 microseconds. Note: the delay is not the time per bit but an additional time per bit. Note: the delay can be set runtime per write / print call. - **uint16_t getDelay()** returns the set delay in microseconds. + +### BitOrder + - **bool setBitOrder(uint8_t bitOrder = LSBFIRST)** set LSBFIRST or MSBFIRST. Returns false for other values. Note: bit order can be changed runtime per write / print call. - **uint8_t getBitOrder()** returns LSBFIRST or MSBFIRST (typical 0 and 1). +### Invert + +(new in 0.1.7) + +- **void setInvert(bool invert = false)** invert the data written. +- **uint16_t getInvert()** idem. + +If the byte written is inverted, the **lastWritten()** will return +the inverted value too. + ### Print interface diff --git a/ShiftOutSlow.cpp b/ShiftOutSlow.cpp index b6ff015..920fef0 100644 --- a/ShiftOutSlow.cpp +++ b/ShiftOutSlow.cpp @@ -1,9 +1,9 @@ // // FILE: ShiftOutSlow.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.6 -// PURPOSE: Arduino library for shiftOut with build-in delay +// VERSION: 0.1.7 // DATE: 2021-05-11 +// PURPOSE: Arduino library for shiftOut with build-in delay // URL: https://github.com/RobTillaart/ShiftOutSlow @@ -28,6 +28,11 @@ size_t ShiftOutSlow::write(const uint8_t data) uint8_t val = data; uint16_t d1 = _delay/2; uint16_t d2 = _delay - d1; + if (_invert) + { + val ^= 0xFF; + } + _value = val; for (uint8_t i = 0; i < 8; ++i) { if (d1) delayMicroseconds(d1); @@ -43,7 +48,6 @@ size_t ShiftOutSlow::write(const uint8_t data) yield(); digitalWrite(_clockPin, LOW); } - _value = data; return 1; } @@ -93,5 +97,17 @@ uint16_t ShiftOutSlow::getDelay() } +void ShiftOutSlow::setInvert(bool invert) +{ + _invert = invert; +} + + +bool ShiftOutSlow::getInvert() +{ + return _invert; +} + + // -- END OF FILE -- diff --git a/ShiftOutSlow.h b/ShiftOutSlow.h index bac4bdb..91280fe 100644 --- a/ShiftOutSlow.h +++ b/ShiftOutSlow.h @@ -2,16 +2,16 @@ // // FILE: ShiftOutSlow.h // AUTHOR: Rob Tillaart -// VERSION: 0.1. -// PURPOSE: Arduino library for shiftOut with build-in delay +// VERSION: 0.1.7 // DATE: 2021-05-11 +// PURPOSE: Arduino library for shiftOut with build-in delay // URL: https://github.com/RobTillaart/ShiftOutSlow #include "Arduino.h" -#define SHIFTOUTSLOW_LIB_VERSION (F("0.1.6")) +#define SHIFTOUTSLOW_LIB_VERSION (F("0.1.7")) class ShiftOutSlow : public Print @@ -33,6 +33,9 @@ class ShiftOutSlow : public Print void setDelay(uint16_t microSeconds = 0); uint16_t getDelay(); + void setInvert(bool invert = false); + bool getInvert(); + private: uint8_t _clockPin = 0; @@ -40,6 +43,7 @@ class ShiftOutSlow : public Print uint8_t _bitOrder = LSBFIRST; uint16_t _delay = 0; uint8_t _value = 0; + bool _invert = false; }; diff --git a/examples/shiftOutSlow_demo/output_0.1.7.txt b/examples/shiftOutSlow_demo/output_0.1.7.txt new file mode 100644 index 0000000..2b08eac --- /dev/null +++ b/examples/shiftOutSlow_demo/output_0.1.7.txt @@ -0,0 +1,3 @@ +IDE: 1.8.19 +BOARD: UNO R3 + diff --git a/keywords.txt b/keywords.txt index 4a431cf..5067b81 100644 --- a/keywords.txt +++ b/keywords.txt @@ -15,6 +15,9 @@ getBitOrder KEYWORD2 setDelay KEYWORD2 getDelay KEYWORD2 +setInvert KEYWORD2 +getInvert KEYWORD2 + # Constants (LITERAL1) SHIFTOUTSLOW_LIB_VERSION LITERAL1 diff --git a/library.json b/library.json index 2d3dfcb..0ef3f4f 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/ShiftOutSlow.git" }, - "version": "0.1.6", + "version": "0.1.7", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 1a60fbf..60ada30 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ShiftOutSlow -version=0.1.6 +version=0.1.7 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for shiftOut with build-in delay - e.g. for 74HC165 From 3141314f7553678dc00a619c43cb7bd4ebdc8257 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Fri, 5 Jun 2026 17:05:59 +0200 Subject: [PATCH 2/2] fix --- examples/shiftOutSlow_demo/output_0.1.7.txt | 16 ++++++++++++++++ examples/shiftOutSlow_demo/shiftOutSlow_demo.ino | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/shiftOutSlow_demo/output_0.1.7.txt b/examples/shiftOutSlow_demo/output_0.1.7.txt index 2b08eac..3e85c90 100644 --- a/examples/shiftOutSlow_demo/output_0.1.7.txt +++ b/examples/shiftOutSlow_demo/output_0.1.7.txt @@ -1,3 +1,19 @@ IDE: 1.8.19 BOARD: UNO R3 +shiftOutSlow_demo.ino +SHIFTOUTSLOW_LIB_VERSION: 0.1.7 + +176 0 22.0 +944 100 118.0 +1752 200 219.0 +2556 300 319.5 +3360 400 420.0 +4164 500 520.5 +4972 600 621.5 +5776 700 722.0 +6572 800 821.5 +7388 900 923.5 +8188 1000 1023.5 + +done... diff --git a/examples/shiftOutSlow_demo/shiftOutSlow_demo.ino b/examples/shiftOutSlow_demo/shiftOutSlow_demo.ino index 57ed364..f78f200 100644 --- a/examples/shiftOutSlow_demo/shiftOutSlow_demo.ino +++ b/examples/shiftOutSlow_demo/shiftOutSlow_demo.ino @@ -37,7 +37,7 @@ void setup() delay(20); } - Serial.println("done..."); + Serial.println("\ndone..."); }