needed for 1620 test code
Fork of ShiftOut by
Diff: ShiftOut.h
- Revision:
- 0:a4f4842715fd
- Child:
- 1:4c2379445f72
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ShiftOut.h Mon May 26 14:57:22 2014 +0000 @@ -0,0 +1,40 @@ +#ifndef SHIFTOUT_H +#define SHIFTOUT_H + +#include <mbed.h> + +class ShiftOut { + + public : + + ShiftOut(PinName clk, PinName data, PinName latch, int8_t registerCount = 8) { + clkout = new DigitalOut(clk); + dataout = new DigitalOut(data); + latchout = new DigitalOut(latch); + this->registerCount = registerCount; + } + + ~ShiftOut() { + delete clkout; + delete dataout; + delete latchout; + } + + void write(int8_t data) { + *latchout = 0; + for(int i = registerCount - 1; i >= 0; i--){ + *clkout = 0; + *dataout = (data & (1 << i)) != 0; + *clkout = 1; + } + *latchout = 1; + } + + private : + DigitalOut *clkout; + DigitalOut *dataout; + DigitalOut *latchout; + int8_t registerCount; +}; + +#endif \ No newline at end of file