diff options
author | Alexander Entinger <consulting@lxrobotics.com> | 2019-09-16 13:19:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-16 13:19:02 +0200 |
commit | 3883e49b385a6745e2693f5b796a20d9ced0483b (patch) | |
tree | 11ffe7194503fdfdf89bb29990ce88ec7f72d141 /cores | |
parent | ffeca151f1eda674b7baf93b91a827f70c9d836f (diff) | |
parent | 4d074e8a54d5395cafbb2c860f55304b329d83ab (diff) |
Merge pull request #82 from luco5826/master
Minor optimization in shiftOut function
Diffstat (limited to 'cores')
-rw-r--r-- | cores/arduino/wiring_shift.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 2b6f7a8..a9b3be5 100644 --- a/cores/arduino/wiring_shift.c +++ b/cores/arduino/wiring_shift.c @@ -42,10 +42,13 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) uint8_t i; for (i = 0; i < 8; i++) { - if (bitOrder == LSBFIRST) - digitalWrite(dataPin, !!(val & (1 << i))); - else - digitalWrite(dataPin, !!(val & (1 << (7 - i)))); + if (bitOrder == LSBFIRST) { + digitalWrite(dataPin, val & 1); + val >>= 1; + } else { + digitalWrite(dataPin, (val & 128) != 0); + val <<= 1; + } digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW); |