Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: ShiftReg/ShiftReg.cpp
- 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;
+}
+