a MIDI-to-Morse code application.
Dependencies: MIDI REnc button mbed morse
Diff: main.cpp
- Revision:
- 4:98b4e2f46789
- Parent:
- 3:993b88218184
- Child:
- 5:decb31e2efa4
--- a/main.cpp Sun Jul 13 02:23:16 2014 +0000 +++ b/main.cpp Sun Jul 13 03:03:51 2014 +0000 @@ -69,35 +69,47 @@ } +class BTN { + +public: + unsigned char CMD; unsigned char STAT; +private: unsigned char FIL; - DigitalIn _Pin(dp13); + DigitalIn _Pin; Ticker _Tick; -void sample_btn() -{ - unsigned char a, b; - - a = _Pin; + void sample_btn() + { + unsigned char a, b; - if (a == FIL) { - b = STAT; - STAT = a; - b = (b ^ a) & a; - if (b) CMD = b; + a = _Pin; + + if (a == FIL) { + b = STAT; + STAT = a; + b = (b ^ a) & a; + if (b) CMD = b; + } + FIL = a; } - FIL = a; -} +public: + BTN(PinName pin) : _Pin(pin) { + _Tick.attach(this, &BTN::sample_btn, 0.01); + } + + +}; + + BTN btn(dp13); int main() { int i; char* ptr; - _Tick.attach(&sample_btn, 0.01); - { __pwm.period(1.0/FREQ); __pwm.write(0.0); @@ -124,9 +136,9 @@ } space(2); - if(CMD) { + if(btn.CMD) { i++; - CMD = 0; + btn.CMD = 0; } } }