diff options
author | luca <luca.errani1@gmail.com> | 2019-04-26 14:32:43 +0200 |
---|---|---|
committer | luca <luca.errani1@gmail.com> | 2019-04-26 14:32:43 +0200 |
commit | 649f978224d79947d679612e4bcb326280f4f963 (patch) | |
tree | a92953cce55a3e9e5b41e2e979f255821fd235d2 /cores | |
parent | 5755ddea49fa69d6c505c772ebee5af5078e2ebf (diff) |
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..042a95a 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); + val <<= 1; + } digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW); |