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 bbd8024..869454e 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.6] - 2026-06-05 +- add setInvert(bool) and getInvert() +- update GitHub actions +- minor edits + ## [0.1.5] - 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 6c49563..d1d18c5 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,16 @@ Arduino library for shiftIn with build-in delay - e.g. for 74HC165. **Experimental** -shiftInSlow 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. +shiftInSlow is a library which has a build in delay (in microseconds) +that allows tuning the time per bit. +This can help to improve reliability e.g. when using long lines. -The dataPin and clockPin are set in the constructor, the delay is configurable per byte send to be able to optimize runtime. +The dataPin and clockPin and bitOrder are set in the constructor. +The (bit) delay is configurable before every byte send to be able +to optimize runtime. +Default there is no delay. + +Feedback as always is welcome. ### Related @@ -35,14 +41,14 @@ The dataPin and clockPin are set in the constructor, the delay is configurable p ## Performance -The performance of **read()** with a delay of 0 microseconds is slower than the default Arduino -**shiftIn()** due to some overhead. +The performance of **read()** with a delay of 0 microseconds is slower + than the default Arduino **shiftIn()** due to some overhead. -The delay requested is split in two (expect rounding errors) to have "nice" looking pulse -with the duty cycle around 50%. +The delay requested is split in two (expect rounding errors) to have +"nice" looking pulse with the duty cycle around 50%. -Performance measurements are meaningless, as the purpose of this library is to -slow the pulse train to a working level. +Performance measurements are meaningless, as the purpose of this library +is to slow down the pulse train to a working level. ## Interface @@ -55,18 +61,37 @@ slow the pulse train to a working level. - **ShiftInSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** constructor, bit order is default set to LSBFIRST. +Default there is no delay (0 us). -### Functions +### Read - **int read()** reads a new value. -- **int lastRead()** returns last value read. -- **void setDelay(uint16_t microseconds = 0)** set delay per bit from 0 .. 65535 microseconds. +- **int lastRead()** returns last value read from cache. + +### Delay + +- **void setDelay(uint16_t microseconds = 0)** set delay per bit +from 0 .. 65535 microseconds. Note that the delay is split in two parts to keep the duty cycle around 50%. Note that odd delays will get a truncating error. - **uint16_t getDelay()** returns the set delay in microseconds. -- **bool setBitOrder(uint8_t bitOrder = LSBFIRST)** set LSBFIRST or MSBFIRST. Returns false for other values. + +### BitOrder + +- **bool setBitOrder(uint8_t bitOrder = LSBFIRST)** set LSBFIRST or MSBFIRST. +Returns false for other values (so bitOrder is not changed). - **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST. +### Invert + +(new in 0.1.6) + +- **void setInvert(bool invert = false)** invert the data read. +- **uint16_t getInvert()** + +If the byte read is inverted, the **lastRead()** will return +the inverted value too. + ## Operation @@ -83,9 +108,6 @@ See examples. - Add a select pin to be more SPI alike? - would allow SPI debugging? -- increase max delay uint32_t ? - - would allow pulses in "second" domain. - - millis() clock iso micros() - fix odd delays rounding error - get uneven duty cycle is result. @@ -93,6 +115,9 @@ See examples. - add examples - adaptive speed example? +- reverse flag to change "BitOrder in software"? + - parameter for read(bool reverse) or lastRead(reverse) + - faster than rereading (if possible) #### Wont @@ -103,7 +128,10 @@ See examples. - set delay in terms of frequency - delay is 'wave length' - set delay in terms of max total time the read may cost. - read16/24/32 to read more bytes is a user task. - +- increase max delay uint32_t ? + - would allow pulses in "second" domain. + - and blocking for long time. + - millis() clock instead of micros() ## Support diff --git a/ShiftInSlow.cpp b/ShiftInSlow.cpp index eeb93cd..8504f74 100644 --- a/ShiftInSlow.cpp +++ b/ShiftInSlow.cpp @@ -1,9 +1,9 @@ // // FILE: ShiftInSlow.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.5 -// PURPOSE: Arduino library for shiftIn with build-in delay +// VERSION: 0.1.6 // DATE: 2021-05-11 +// PURPOSE: Arduino library for shiftIn with build-in delay // URL: https://github.com/RobTillaart/ShiftInSlow @@ -39,6 +39,10 @@ int ShiftInSlow::read() digitalWrite(_clockPin, LOW); if (_delay > 0) delayMicroseconds(_delay / 2); } + if (_invert) + { + _value ^= 0xFF; + } return _value; } @@ -77,5 +81,17 @@ uint16_t ShiftInSlow::getDelay() } +void ShiftInSlow::setInvert(bool invert) +{ + _invert = invert; +} + + +uint16_t ShiftInSlow::getInvert() +{ + return _invert; +} + + // -- END OF FILE -- diff --git a/ShiftInSlow.h b/ShiftInSlow.h index 8b7d7fe..75ec9d9 100644 --- a/ShiftInSlow.h +++ b/ShiftInSlow.h @@ -2,16 +2,16 @@ // // FILE: ShiftInSlow.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.5 -// PURPOSE: Arduino library for shiftIn with build-in delay +// VERSION: 0.1.6 // DATE: 2021-05-11 +// PURPOSE: Arduino library for shiftIn with build-in delay // URL: https://github.com/RobTillaart/ShiftInSlow #include "Arduino.h" -#define SHIFTINSLOW_LIB_VERSION (F("0.1.5")) +#define SHIFTINSLOW_LIB_VERSION (F("0.1.6")) class ShiftInSlow @@ -29,6 +29,9 @@ class ShiftInSlow void setDelay(uint16_t microseconds = 0); uint16_t getDelay(); + void setInvert(bool invert = false); + uint16_t getInvert(); + private: uint8_t _clockPin = 0; @@ -36,6 +39,7 @@ class ShiftInSlow uint8_t _bitOrder = LSBFIRST; uint16_t _delay = 0; uint8_t _value = 0; + bool _invert = false; }; diff --git a/examples/shiftInSlow_demo/output_0.1.6.txt b/examples/shiftInSlow_demo/output_0.1.6.txt new file mode 100644 index 0000000..a4044d1 --- /dev/null +++ b/examples/shiftInSlow_demo/output_0.1.6.txt @@ -0,0 +1,109 @@ +IDE: 1.8.19 +BOARD: UNO R3 + +shiftInSlow_demo.ino +SHIFTINSLOW_LIB_VERSION: 0.1.6 + +0 204 25.5 +10 264 33.0 +20 348 43.5 +30 424 53.0 +40 504 63.0 +50 584 73.0 +60 668 83.5 +70 748 93.5 +80 828 103.5 +90 908 113.5 +100 992 124.0 +110 1068 133.5 +120 1152 144.0 +130 1236 154.5 +140 1312 164.0 +150 1392 174.0 +160 1468 183.5 +170 1556 194.5 +180 1636 204.5 +190 1716 214.5 +200 1788 223.5 +210 1876 234.5 +220 1956 244.5 +230 2036 254.5 +240 2116 264.5 +250 2200 275.0 +260 2276 284.5 +270 2356 294.5 +280 2444 305.5 +290 2524 315.5 +300 2600 325.0 +310 2680 335.0 +320 2764 345.5 +330 2844 355.5 +340 2920 365.0 +350 3000 375.0 +360 3080 385.0 +370 3160 395.0 +380 3248 406.0 +390 3324 415.5 +400 3404 425.5 +410 3488 436.0 +420 3568 446.0 +430 3648 456.0 +440 3728 466.0 +450 3808 476.0 +460 3884 485.5 +470 3968 496.0 +480 4048 506.0 +490 4128 516.0 +500 4208 526.0 +510 4288 536.0 +520 4376 547.0 +530 4448 556.0 +540 4528 566.0 +550 4612 576.5 +560 4688 586.0 +570 4772 596.5 +580 4856 607.0 +590 4932 616.5 +600 5016 627.0 +610 5092 636.5 +620 5176 647.0 +630 5256 657.0 +640 5332 666.5 +650 5416 677.0 +660 5496 687.0 +670 5580 697.5 +680 5660 707.5 +690 5740 717.5 +700 5820 727.5 +710 5896 737.0 +720 5980 747.5 +730 6060 757.5 +740 6140 767.5 +750 6220 777.5 +760 6308 788.5 +770 6380 797.5 +780 6464 808.0 +790 6548 818.5 +800 6628 828.5 +810 6708 838.5 +820 6784 848.0 +830 6868 858.5 +840 6940 867.5 +850 7024 878.0 +860 7108 888.5 +870 7184 898.0 +880 7264 908.0 +890 7344 918.0 +900 7428 928.5 +910 7504 938.0 +920 7588 948.5 +930 7668 958.5 +940 7752 969.0 +950 7828 978.5 +960 7908 988.5 +970 7996 999.5 +980 8072 1009.0 +990 8152 1019.0 +1000 8232 1029.0 + +done... diff --git a/examples/shiftInSlow_demo/shiftInSlow_demo.ino b/examples/shiftInSlow_demo/shiftInSlow_demo.ino index 1663d4d..1eb9ff7 100644 --- a/examples/shiftInSlow_demo/shiftInSlow_demo.ino +++ b/examples/shiftInSlow_demo/shiftInSlow_demo.ino @@ -37,7 +37,7 @@ void setup() Serial.print("\n"); } - Serial.println("done..."); + Serial.println("\ndone..."); } @@ -46,4 +46,4 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/keywords.txt b/keywords.txt index fec0fd1..e55ce04 100644 --- a/keywords.txt +++ b/keywords.txt @@ -15,6 +15,9 @@ getBitOrder KEYWORD2 setDelay KEYWORD2 getDelay KEYWORD2 +setInvert KEYWORD2 +getInvert KEYWORD2 + # Constants (LITERAL1) SHIFTINSLOW_LIB_VERSION LITERAL1 diff --git a/library.json b/library.json index f38235d..556ce90 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/ShiftInSlow.git" }, - "version": "0.1.5", + "version": "0.1.6", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 405f202..95f7e70 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ShiftInSlow -version=0.1.5 +version=0.1.6 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for shiftIn with build-in delay - e.g. for 74HC165