Template for the ELEC1620 End of year exam

Dependencies:   mbed

Revision:
0:54721f063ac8
diff -r 000000000000 -r 54721f063ac8 ShiftReg/ShiftReg.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ShiftReg/ShiftReg.cpp	Fri Mar 22 13:11:07 2019 +0000
@@ -0,0 +1,28 @@
+#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;
+        wait_us(20);
+    }
+    *latchout = 1;
+}
+