Yudong Xiao
/
pokemon
This is test version of Pokemongo game. ELEC 2645 final project.
Diff: pokeball/ShiftReg.cpp
- Revision:
- 0:819c2d6a69ac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pokeball/ShiftReg.cpp Thu Apr 15 15:35:12 2021 +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