needed for 1620 test code

Fork of ShiftOut by Ollie Milton

Committer:
ollie8
Date:
Mon May 26 15:11:18 2014 +0000
Revision:
1:4c2379445f72
Parent:
0:a4f4842715fd
Child:
2:78bb6ead1c28
change write method to take an int as its argument

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ollie8 0:a4f4842715fd 1 #ifndef SHIFTOUT_H
ollie8 0:a4f4842715fd 2 #define SHIFTOUT_H
ollie8 0:a4f4842715fd 3
ollie8 0:a4f4842715fd 4 #include <mbed.h>
ollie8 0:a4f4842715fd 5
ollie8 0:a4f4842715fd 6 class ShiftOut {
ollie8 0:a4f4842715fd 7
ollie8 0:a4f4842715fd 8 public :
ollie8 0:a4f4842715fd 9
ollie8 0:a4f4842715fd 10 ShiftOut(PinName clk, PinName data, PinName latch, int8_t registerCount = 8) {
ollie8 0:a4f4842715fd 11 clkout = new DigitalOut(clk);
ollie8 0:a4f4842715fd 12 dataout = new DigitalOut(data);
ollie8 0:a4f4842715fd 13 latchout = new DigitalOut(latch);
ollie8 0:a4f4842715fd 14 this->registerCount = registerCount;
ollie8 0:a4f4842715fd 15 }
ollie8 0:a4f4842715fd 16
ollie8 0:a4f4842715fd 17 ~ShiftOut() {
ollie8 0:a4f4842715fd 18 delete clkout;
ollie8 0:a4f4842715fd 19 delete dataout;
ollie8 0:a4f4842715fd 20 delete latchout;
ollie8 0:a4f4842715fd 21 }
ollie8 0:a4f4842715fd 22
ollie8 1:4c2379445f72 23 void write(int data) {
ollie8 0:a4f4842715fd 24 *latchout = 0;
ollie8 0:a4f4842715fd 25 for(int i = registerCount - 1; i >= 0; i--){
ollie8 0:a4f4842715fd 26 *clkout = 0;
ollie8 0:a4f4842715fd 27 *dataout = (data & (1 << i)) != 0;
ollie8 0:a4f4842715fd 28 *clkout = 1;
ollie8 0:a4f4842715fd 29 }
ollie8 0:a4f4842715fd 30 *latchout = 1;
ollie8 0:a4f4842715fd 31 }
ollie8 0:a4f4842715fd 32
ollie8 0:a4f4842715fd 33 private :
ollie8 0:a4f4842715fd 34 DigitalOut *clkout;
ollie8 0:a4f4842715fd 35 DigitalOut *dataout;
ollie8 0:a4f4842715fd 36 DigitalOut *latchout;
ollie8 0:a4f4842715fd 37 int8_t registerCount;
ollie8 0:a4f4842715fd 38 };
ollie8 0:a4f4842715fd 39
ollie8 0:a4f4842715fd 40 #endif