Simple shift register library

Dependents:   1620_App_Board_Shift_Register 1620_App_Board_UART_getc 1620_Project_Template 1620_Project_Template ... more

Revision:
0:4922f5f8bfa9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ShiftReg.cpp	Mon Feb 20 20:37:06 2017 +0000
@@ -0,0 +1,26 @@
+#include "ShiftReg.h"
+
+ShiftReg::ShiftReg()
+{
+    clkout = new DigitalOut(p7);
+    dataout = new DigitalOut(p5);
+    latchout = new DigitalOut(p30);
+}
+
+ShiftReg::~ShiftReg()
+{
+    delete clkout;
+    delete dataout;
+    delete latchout;
+}
+
+void ShiftReg::write(int data)
+{
+    *latchout = 0;
+    for (int i = 7; i >=  0; i--) {
+        *clkout = 0;
+        *dataout = (data & (1 << i)) != 0;
+        *clkout = 1;
+    }
+    *latchout = 1;
+}
\ No newline at end of file