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.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
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
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

Expand Down
22 changes: 19 additions & 3 deletions ShiftOutSlow.cpp
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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);
Expand All @@ -43,7 +48,6 @@ size_t ShiftOutSlow::write(const uint8_t data)
yield();
digitalWrite(_clockPin, LOW);
}
_value = data;
return 1;
}

Expand Down Expand Up @@ -93,5 +97,17 @@ uint16_t ShiftOutSlow::getDelay()
}


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


bool ShiftOutSlow::getInvert()
{
return _invert;
}


// -- END OF FILE --

10 changes: 7 additions & 3 deletions ShiftOutSlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,13 +33,17 @@ 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;
uint8_t _dataPin = 0;
uint8_t _bitOrder = LSBFIRST;
uint16_t _delay = 0;
uint8_t _value = 0;
bool _invert = false;
};


Expand Down
19 changes: 19 additions & 0 deletions examples/shiftOutSlow_demo/output_0.1.7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +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...
2 changes: 1 addition & 1 deletion examples/shiftOutSlow_demo/shiftOutSlow_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void setup()
delay(20);
}

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


Expand Down
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)
SHIFTOUTSLOW_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/ShiftOutSlow.git"
},
"version": "0.1.6",
"version": "0.1.7",
"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=ShiftOutSlow
version=0.1.6
version=0.1.7
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for shiftOut with build-in delay - e.g. for 74HC165
Expand Down
Loading