Dance Dance Revolution program for main mbed
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
joystick.h@0:8a02ac09eae0, 2016-04-29 (annotated)
- Committer:
- wliu88
- Date:
- Fri Apr 29 02:04:07 2016 +0000
- Revision:
- 0:8a02ac09eae0
new
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wliu88 | 0:8a02ac09eae0 | 1 | #include "mbed.h" |
wliu88 | 0:8a02ac09eae0 | 2 | |
wliu88 | 0:8a02ac09eae0 | 3 | class Nav_Switch |
wliu88 | 0:8a02ac09eae0 | 4 | { |
wliu88 | 0:8a02ac09eae0 | 5 | public: |
wliu88 | 0:8a02ac09eae0 | 6 | Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire, |
wliu88 | 0:8a02ac09eae0 | 7 | volatile bool* u, volatile bool* d, volatile bool* l, volatile bool* r, volatile bool* f, volatile int* counter); |
wliu88 | 0:8a02ac09eae0 | 8 | //boolean functions to test each switch |
wliu88 | 0:8a02ac09eae0 | 9 | void up(); |
wliu88 | 0:8a02ac09eae0 | 10 | void down(); |
wliu88 | 0:8a02ac09eae0 | 11 | void left(); |
wliu88 | 0:8a02ac09eae0 | 12 | void right(); |
wliu88 | 0:8a02ac09eae0 | 13 | void fire(); |
wliu88 | 0:8a02ac09eae0 | 14 | private: |
wliu88 | 0:8a02ac09eae0 | 15 | InterruptIn _up; |
wliu88 | 0:8a02ac09eae0 | 16 | InterruptIn _down; |
wliu88 | 0:8a02ac09eae0 | 17 | InterruptIn _left; |
wliu88 | 0:8a02ac09eae0 | 18 | InterruptIn _right; |
wliu88 | 0:8a02ac09eae0 | 19 | InterruptIn _fire; |
wliu88 | 0:8a02ac09eae0 | 20 | volatile bool* _u; |
wliu88 | 0:8a02ac09eae0 | 21 | volatile bool* _d; |
wliu88 | 0:8a02ac09eae0 | 22 | volatile bool* _l; |
wliu88 | 0:8a02ac09eae0 | 23 | volatile bool* _r; |
wliu88 | 0:8a02ac09eae0 | 24 | volatile bool* _f; |
wliu88 | 0:8a02ac09eae0 | 25 | volatile int* _counter; |
wliu88 | 0:8a02ac09eae0 | 26 | |
wliu88 | 0:8a02ac09eae0 | 27 | }; |
wliu88 | 0:8a02ac09eae0 | 28 | Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire, |
wliu88 | 0:8a02ac09eae0 | 29 | volatile bool* u, volatile bool* d, volatile bool* l, volatile bool* r, volatile bool* f, |
wliu88 | 0:8a02ac09eae0 | 30 | volatile int* counter): |
wliu88 | 0:8a02ac09eae0 | 31 | _up(up), _down(down), _left(left), _right(right), _fire(fire), |
wliu88 | 0:8a02ac09eae0 | 32 | _u(u), _d(d), _l(l), _r(r), _f(f), |
wliu88 | 0:8a02ac09eae0 | 33 | _counter(counter) |
wliu88 | 0:8a02ac09eae0 | 34 | { |
wliu88 | 0:8a02ac09eae0 | 35 | _up.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise |
wliu88 | 0:8a02ac09eae0 | 36 | _down.mode(PullUp); |
wliu88 | 0:8a02ac09eae0 | 37 | _left.mode(PullUp); |
wliu88 | 0:8a02ac09eae0 | 38 | _right.mode(PullUp); |
wliu88 | 0:8a02ac09eae0 | 39 | _fire.mode(PullUp); |
wliu88 | 0:8a02ac09eae0 | 40 | wait(0.001); //delays just a bit for pullups to pull inputs high |
wliu88 | 0:8a02ac09eae0 | 41 | _up.fall(this, &Nav_Switch::up); |
wliu88 | 0:8a02ac09eae0 | 42 | _down.fall(this, &Nav_Switch::down); |
wliu88 | 0:8a02ac09eae0 | 43 | _left.fall(this, &Nav_Switch::left); |
wliu88 | 0:8a02ac09eae0 | 44 | _right.fall(this, &Nav_Switch::right); |
wliu88 | 0:8a02ac09eae0 | 45 | _fire.fall(this, &Nav_Switch::fire); |
wliu88 | 0:8a02ac09eae0 | 46 | } |
wliu88 | 0:8a02ac09eae0 | 47 | inline void Nav_Switch::up() |
wliu88 | 0:8a02ac09eae0 | 48 | { |
wliu88 | 0:8a02ac09eae0 | 49 | (*_u) = true; |
wliu88 | 0:8a02ac09eae0 | 50 | (*_counter) = ((*_counter) + 2 - 1) % 2; |
wliu88 | 0:8a02ac09eae0 | 51 | } |
wliu88 | 0:8a02ac09eae0 | 52 | inline void Nav_Switch::down() |
wliu88 | 0:8a02ac09eae0 | 53 | { |
wliu88 | 0:8a02ac09eae0 | 54 | (*_d) = true; |
wliu88 | 0:8a02ac09eae0 | 55 | (*_counter) = ((*_counter) + 1) % 2; |
wliu88 | 0:8a02ac09eae0 | 56 | } |
wliu88 | 0:8a02ac09eae0 | 57 | inline void Nav_Switch::left() |
wliu88 | 0:8a02ac09eae0 | 58 | { |
wliu88 | 0:8a02ac09eae0 | 59 | (*_l) = true; |
wliu88 | 0:8a02ac09eae0 | 60 | } |
wliu88 | 0:8a02ac09eae0 | 61 | inline void Nav_Switch::right() |
wliu88 | 0:8a02ac09eae0 | 62 | { |
wliu88 | 0:8a02ac09eae0 | 63 | (*_r) = true; |
wliu88 | 0:8a02ac09eae0 | 64 | } |
wliu88 | 0:8a02ac09eae0 | 65 | inline void Nav_Switch::fire() |
wliu88 | 0:8a02ac09eae0 | 66 | { |
wliu88 | 0:8a02ac09eae0 | 67 | (*_f) = true; |
wliu88 | 0:8a02ac09eae0 | 68 | } |