Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
62 changes: 45 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -83,16 +108,16 @@ 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.

#### Could

- 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

Expand All @@ -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

Expand Down
20 changes: 18 additions & 2 deletions ShiftInSlow.cpp
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -39,6 +39,10 @@ int ShiftInSlow::read()
digitalWrite(_clockPin, LOW);
if (_delay > 0) delayMicroseconds(_delay / 2);
}
if (_invert)
{
_value ^= 0xFF;
}
return _value;
}

Expand Down Expand Up @@ -77,5 +81,17 @@ uint16_t ShiftInSlow::getDelay()
}


void ShiftInSlow::setInvert(bool invert)
{
_invert = invert;
}


uint16_t ShiftInSlow::getInvert()
{
return _invert;
}


// -- END OF FILE --

10 changes: 7 additions & 3 deletions ShiftInSlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,13 +29,17 @@ class ShiftInSlow
void setDelay(uint16_t microseconds = 0);
uint16_t getDelay();

void setInvert(bool invert = false);
uint16_t getInvert();


private:
uint8_t _clockPin = 0;
uint8_t _dataPin = 0;
uint8_t _bitOrder = LSBFIRST;
uint16_t _delay = 0;
uint8_t _value = 0;
bool _invert = false;
};


Expand Down
109 changes: 109 additions & 0 deletions examples/shiftInSlow_demo/output_0.1.6.txt
Original file line number Diff line number Diff line change
@@ -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...
4 changes: 2 additions & 2 deletions examples/shiftInSlow_demo/shiftInSlow_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void setup()
Serial.print("\n");
}

Serial.println("done...");
Serial.println("\ndone...");
}


Expand All @@ -46,4 +46,4 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ getBitOrder KEYWORD2
setDelay KEYWORD2
getDelay KEYWORD2

setInvert KEYWORD2
getInvert KEYWORD2


# Constants (LITERAL1)
SHIFTINSLOW_LIB_VERSION LITERAL1
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ShiftInSlow
version=0.1.5
version=0.1.6
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for shiftIn with build-in delay - e.g. for 74HC165
Expand Down
Loading