Tamas Titusz Ban
/
ELEC1620_ExamTemplate_2019
Template for the ELEC1620 End of year exam
Diff: ShiftReg/ShiftReg.cpp
- Revision:
- 0:54721f063ac8
--- /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; +} +