Yudong Xiao
/
pokemon
This is test version of Pokemongo game. ELEC 2645 final project.
pokeball/ShiftReg.cpp@0:819c2d6a69ac, 2021-04-15 (annotated)
- Committer:
- shalwego
- Date:
- Thu Apr 15 15:35:12 2021 +0000
- Revision:
- 0:819c2d6a69ac
Issue about music playing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shalwego | 0:819c2d6a69ac | 1 | #include "ShiftReg.h" |
shalwego | 0:819c2d6a69ac | 2 | |
shalwego | 0:819c2d6a69ac | 3 | ShiftReg::ShiftReg() |
shalwego | 0:819c2d6a69ac | 4 | { |
shalwego | 0:819c2d6a69ac | 5 | clkout = new DigitalOut(p7); |
shalwego | 0:819c2d6a69ac | 6 | dataout = new DigitalOut(p5); |
shalwego | 0:819c2d6a69ac | 7 | latchout = new DigitalOut(p30); |
shalwego | 0:819c2d6a69ac | 8 | } |
shalwego | 0:819c2d6a69ac | 9 | |
shalwego | 0:819c2d6a69ac | 10 | ShiftReg::~ShiftReg() |
shalwego | 0:819c2d6a69ac | 11 | { |
shalwego | 0:819c2d6a69ac | 12 | delete clkout; |
shalwego | 0:819c2d6a69ac | 13 | delete dataout; |
shalwego | 0:819c2d6a69ac | 14 | delete latchout; |
shalwego | 0:819c2d6a69ac | 15 | } |
shalwego | 0:819c2d6a69ac | 16 | |
shalwego | 0:819c2d6a69ac | 17 | void ShiftReg::write(int data) |
shalwego | 0:819c2d6a69ac | 18 | { |
shalwego | 0:819c2d6a69ac | 19 | *latchout = 0; |
shalwego | 0:819c2d6a69ac | 20 | for (int i = 7; i >= 0; i--) { |
shalwego | 0:819c2d6a69ac | 21 | *clkout = 0; |
shalwego | 0:819c2d6a69ac | 22 | *dataout = (data & (1 << i)) != 0; |
shalwego | 0:819c2d6a69ac | 23 | *clkout = 1; |
shalwego | 0:819c2d6a69ac | 24 | } |
shalwego | 0:819c2d6a69ac | 25 | *latchout = 1; |
shalwego | 0:819c2d6a69ac | 26 | } |