Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD mbed MMA8451Q TSI
Button.cpp@2:86de87ec731a, 2015-08-14 (annotated)
- Committer:
- mfurlanetto
- Date:
- Fri Aug 14 13:56:10 2015 +0000
- Revision:
- 2:86de87ec731a
- Parent:
- 1:47973f27d645
- Child:
- 3:a703eda2b125
ora le frequenze vengono impostate nel callback dell'interrupt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfurlanetto | 0:f48fccfff709 | 1 | #include "mbed.h" |
mfurlanetto | 0:f48fccfff709 | 2 | #include "Speaker.h" |
mfurlanetto | 0:f48fccfff709 | 3 | |
mfurlanetto | 0:f48fccfff709 | 4 | class Button { |
mfurlanetto | 0:f48fccfff709 | 5 | public: |
mfurlanetto | 2:86de87ec731a | 6 | Button(PinName pin, int note, int* buffer, DigitalOut* myled) : _interrupt(pin) { |
mfurlanetto | 0:f48fccfff709 | 7 | _code=note; |
mfurlanetto | 0:f48fccfff709 | 8 | led=myled; |
mfurlanetto | 1:47973f27d645 | 9 | noteRegister=buffer; |
mfurlanetto | 1:47973f27d645 | 10 | _interrupt.rise(this, &Button::release); |
mfurlanetto | 1:47973f27d645 | 11 | _interrupt.fall(this, &Button::press); |
mfurlanetto | 2:86de87ec731a | 12 | pressTimes=0; |
mfurlanetto | 0:f48fccfff709 | 13 | } |
mfurlanetto | 0:f48fccfff709 | 14 | |
mfurlanetto | 0:f48fccfff709 | 15 | void press() { |
mfurlanetto | 2:86de87ec731a | 16 | if(pressTimes==0) |
mfurlanetto | 2:86de87ec731a | 17 | { |
mfurlanetto | 2:86de87ec731a | 18 | *noteRegister+=_code; |
mfurlanetto | 2:86de87ec731a | 19 | pressTimes++; |
mfurlanetto | 2:86de87ec731a | 20 | } |
mfurlanetto | 1:47973f27d645 | 21 | *led=0; |
mfurlanetto | 0:f48fccfff709 | 22 | } |
mfurlanetto | 0:f48fccfff709 | 23 | |
mfurlanetto | 1:47973f27d645 | 24 | void release() { |
mfurlanetto | 2:86de87ec731a | 25 | *noteRegister-=_code*pressTimes; |
mfurlanetto | 2:86de87ec731a | 26 | pressTimes=0; |
mfurlanetto | 1:47973f27d645 | 27 | *led=1; |
mfurlanetto | 0:f48fccfff709 | 28 | } |
mfurlanetto | 0:f48fccfff709 | 29 | |
mfurlanetto | 0:f48fccfff709 | 30 | private: |
mfurlanetto | 0:f48fccfff709 | 31 | InterruptIn _interrupt; |
mfurlanetto | 0:f48fccfff709 | 32 | int _code; |
mfurlanetto | 2:86de87ec731a | 33 | int* noteRegister; |
mfurlanetto | 0:f48fccfff709 | 34 | DigitalOut* led; |
mfurlanetto | 2:86de87ec731a | 35 | int pressTimes; |
mfurlanetto | 0:f48fccfff709 | 36 | }; |