
Enpra example for TA8428
main.cpp@0:c6fc29c5ecd0, 2013-05-29 (annotated)
- Committer:
- ogata_lab
- Date:
- Wed May 29 13:03:46 2013 +0000
- Revision:
- 0:c6fc29c5ecd0
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ogata_lab | 0:c6fc29c5ecd0 | 1 | #include "mbed.h" |
ogata_lab | 0:c6fc29c5ecd0 | 2 | #include "TA8428.h" |
ogata_lab | 0:c6fc29c5ecd0 | 3 | |
ogata_lab | 0:c6fc29c5ecd0 | 4 | DigitalIn sw01(p19); |
ogata_lab | 0:c6fc29c5ecd0 | 5 | TA8428 driver(p21, p22); |
ogata_lab | 0:c6fc29c5ecd0 | 6 | |
ogata_lab | 0:c6fc29c5ecd0 | 7 | bool old_sw = false; |
ogata_lab | 0:c6fc29c5ecd0 | 8 | bool direction_cw = true; |
ogata_lab | 0:c6fc29c5ecd0 | 9 | |
ogata_lab | 0:c6fc29c5ecd0 | 10 | int main() { |
ogata_lab | 0:c6fc29c5ecd0 | 11 | while(1) { |
ogata_lab | 0:c6fc29c5ecd0 | 12 | bool new_sw = sw01 == 0; |
ogata_lab | 0:c6fc29c5ecd0 | 13 | if (!old_sw && new_sw) { |
ogata_lab | 0:c6fc29c5ecd0 | 14 | direction_cw = !direction_cw; |
ogata_lab | 0:c6fc29c5ecd0 | 15 | } |
ogata_lab | 0:c6fc29c5ecd0 | 16 | old_sw = new_sw; |
ogata_lab | 0:c6fc29c5ecd0 | 17 | |
ogata_lab | 0:c6fc29c5ecd0 | 18 | if (direction_cw) { |
ogata_lab | 0:c6fc29c5ecd0 | 19 | driver.drive(0.5); |
ogata_lab | 0:c6fc29c5ecd0 | 20 | } else { |
ogata_lab | 0:c6fc29c5ecd0 | 21 | driver.drive(-0.5); |
ogata_lab | 0:c6fc29c5ecd0 | 22 | } |
ogata_lab | 0:c6fc29c5ecd0 | 23 | |
ogata_lab | 0:c6fc29c5ecd0 | 24 | } |
ogata_lab | 0:c6fc29c5ecd0 | 25 | } |