Skip to content

Commit 4f22980

Browse files
committed
0.1.0 shiftOutSLow
1 parent d2ce294 commit 4f22980

File tree

13 files changed

+420
-0
lines changed

13 files changed

+420
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
- leonardo
6+
- due
7+
- zero
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
arduino_ci:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: Arduino-CI/action@master
13+
# Arduino-CI/[email protected]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/shiftOutSlow/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021-2021 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/shiftOutSlow/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/ShiftOutSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ShiftOutSlow/blob/master/LICENSE)
4+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ShiftOutSlow.svg?maxAge=3600)](https://github.com/RobTillaart/ShiftOutSlow/releases)
5+
6+
# ShiftOutSlow
7+
8+
Arduino library for shiftOut with build-in delay - e.g. for 74HC595
9+
10+
A library for shiftInSlow also exist.
11+
12+
## Description
13+
14+
15+
ShiftOutSlow is an experimental library that has a build in delay (in microseconds) that allows tuning the time per bit.
16+
This allows one to improve reliability e.g. when using longer lines.
17+
18+
The datapin and clockpin are set in the constructor, the delay is settable per byte send to be able to optimize runtime.
19+
20+
ShiftOutSlow implements the print interface.
21+
22+
23+
## Performance
24+
25+
The performance of **write()** with a delay of 0 microseconds is slower than the default Arduino
26+
**shiftOut()** due to some overhead.
27+
28+
The delay requested is split in two (expect rounding errors) to have "nice" looking pulses.
29+
30+
31+
## Interface
32+
33+
The interface exists of the following functions:
34+
- **ShiftOutSlow(datapin, clockpin, bitorder = LSBFIRST)** constructor.
35+
- **size_t write(uint8_t data)** writes a new value
36+
- **uint8_t lastWritten()** returns last value written
37+
- **void setDelay(uint16_t microseconds)** set delay per bit from 0 .. 65535 microseconds.
38+
- **uint16_t getDelay()** returns the set delay in microseconds.
39+
- **bool setBitOrder(bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
40+
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST
41+
42+
43+
## Notes
44+
45+
- to be tested
46+
47+
48+
## Operation
49+
50+
See examples
51+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// FILE: ShiftOutSlow.cpp
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: Arduino library for shiftOut with build-in delay
6+
// DATE: 2021-05-11
7+
// URL: https://github.com/RobTillaart/ShiftOutSlow
8+
9+
10+
#include "ShiftOutSlow.h"
11+
12+
13+
ShiftOutSlow::ShiftOutSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder)
14+
{
15+
_clockPin = clockPin;
16+
_dataPin = dataPin;
17+
_bitOrder = bitOrder;
18+
_value = 0;
19+
pinMode(_dataPin, OUTPUT);
20+
pinMode(_clockPin, OUTPUT);
21+
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
22+
digitalWrite(_clockPin, LOW); // assume rising pulses from clock
23+
}
24+
25+
26+
size_t ShiftOutSlow::write(const uint8_t data)
27+
{
28+
uint8_t val = data;
29+
for (uint8_t i = 0; i < 8; ++i)
30+
{
31+
if (_delay > 0) delayMicroseconds(_delay/2);
32+
if (_bitOrder == LSBFIRST) {
33+
digitalWrite(_dataPin, val & 0x01);
34+
val >>= 1;
35+
} else {
36+
digitalWrite(_dataPin, (val & 0x80) != 0);
37+
val <<= 1;
38+
}
39+
digitalWrite(_clockPin, HIGH);
40+
if (_delay > 0) delayMicroseconds(_delay/2);
41+
yield();
42+
digitalWrite(_clockPin, LOW);
43+
}
44+
_value = data;
45+
return 1;
46+
}
47+
48+
49+
bool ShiftOutSlow::setBitOrder(const uint8_t bitOrder)
50+
{
51+
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
52+
{
53+
_bitOrder = bitOrder;
54+
return true;
55+
};
56+
return false;
57+
}
58+
59+
// -- END OF FILE --
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
//
3+
// FILE: ShiftOutSlow.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// PURPOSE: Arduino library for shiftOut with build-in delay
7+
// DATE: 2021-05-11
8+
// URL: https://github.com/RobTillaart/ShiftOutSlow
9+
//
10+
11+
12+
#include "Arduino.h"
13+
14+
15+
#define SHIFTOUTSLOW_LIB_VERSION (F("0.1.0"))
16+
17+
18+
class ShiftOutSlow : public Print
19+
{
20+
public:
21+
// bitorder = { LSBFIRST, MSBFIRST };
22+
ShiftOutSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder = LSBFIRST);
23+
24+
size_t write(const uint8_t data);
25+
uint8_t lastWritten(void) { return _value; };
26+
27+
bool setBitOrder(const uint8_t bitOrder);
28+
uint8_t getBitOrder(void) { return _bitOrder; };
29+
30+
void setDelay(uint16_t d) { _delay = d; };
31+
uint16_t getDelay() { return _delay; };
32+
33+
34+
private:
35+
uint8_t _clockPin = 0 ;
36+
uint8_t _dataPin = 0;
37+
uint8_t _bitOrder = LSBFIRST;
38+
uint16_t _delay = 0;
39+
uint8_t _value = 0;
40+
};
41+
42+
// -- END OF FILE --
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// FILE: shiftOutSlow_demo.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: test sketch
6+
// URL: https://github.com/RobTillaart/ShiftOutSlow
7+
//
8+
9+
10+
#include "ShiftOutSlow.h"
11+
12+
13+
ShiftOutSlow SOS(12, 13, LSBFIRST);
14+
15+
volatile int x = 0;
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println(__FILE__);
21+
Serial.println(SHIFTOUTSLOW_LIB_VERSION);
22+
23+
for (uint16_t d = 0; d < 1000; d += 10)
24+
{
25+
SOS.setDelay(d);
26+
uint32_t start = micros();
27+
x = SOS.write(0x55);
28+
uint32_t stop = micros();
29+
float duration = stop - start;
30+
Serial.print(stop - start);
31+
Serial.print("\t");
32+
Serial.println(duration / 8, 1);
33+
}
34+
35+
Serial.println("done...");
36+
}
37+
38+
void loop()
39+
{
40+
}
41+
42+
// -- END OF FILE --
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Syntax Coloring Map For ShiftOutSlow
2+
3+
# Datatypes (KEYWORD1)
4+
ShiftOutSlow KEYWORD1
5+
6+
7+
# Methods and Functions (KEYWORD2)
8+
read KEYWORD2
9+
lastRead KEYWORD2
10+
setBitOrder KEYWORD2
11+
getBitOrder KEYWORD2
12+
setDelay KEYWORD2
13+
getDelay KEYWORD2
14+
15+
16+
# Constants (LITERAL1)
17+
SHIFTOUTSLOW_LIB_VERSION LITERAL1
18+

0 commit comments

Comments
 (0)