From 6b6d46c3e1fa2c05aee87d84c197ea620efb7370 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 11 Aug 2010 22:59:00 +0000 Subject: Adding shiftIn() from Wiring (no count or delaytime though). --- cores/arduino/wiring_shift.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'cores/arduino/wiring_shift.c') diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 956f864..cfe7867 100755 --- a/cores/arduino/wiring_shift.c +++ b/cores/arduino/wiring_shift.c @@ -24,9 +24,24 @@ #include "wiring_private.h" -void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val) +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { + uint8_t value = 0; + uint8_t i; + + for (i = 0; i < 8; ++i) { + digitalWrite(clockPin, HIGH); + if (bitOrder == LSBFIRST) + value |= digitalRead(dataPin) << i; + else + value |= digitalRead(dataPin) << (7 - i); + digitalWrite(clockPin, LOW); + } + return value; +} + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) { - int i; + uint8_t i; for (i = 0; i < 8; i++) { if (bitOrder == LSBFIRST) -- cgit v1.2.3-18-g5258