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: USBDevice mbed-rtos mbed
Fork of JoyStick by
AnalogInFiltered.cpp@0:33bc88c4ab31, 2013-08-28 (annotated)
- Committer:
- rvt
- Date:
- Wed Aug 28 02:33:03 2013 +0000
- Revision:
- 0:33bc88c4ab31
- Child:
- 2:ae7a31a3c618
Initial release with RTOS
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rvt | 0:33bc88c4ab31 | 1 | #include "AnalogInFiltered.h" |
| rvt | 0:33bc88c4ab31 | 2 | |
| rvt | 0:33bc88c4ab31 | 3 | |
| rvt | 0:33bc88c4ab31 | 4 | AnalogInFiltered::AnalogInFiltered(AnalogFilterInterface *filter, PinName pin) { |
| rvt | 0:33bc88c4ab31 | 5 | _ain = new AnalogIn(pin); |
| rvt | 0:33bc88c4ab31 | 6 | _filter = filter; |
| rvt | 0:33bc88c4ab31 | 7 | _lastValue=0; |
| rvt | 0:33bc88c4ab31 | 8 | } |
| rvt | 0:33bc88c4ab31 | 9 | |
| rvt | 0:33bc88c4ab31 | 10 | AnalogInFiltered::~AnalogInFiltered() { |
| rvt | 0:33bc88c4ab31 | 11 | delete(_ain); |
| rvt | 0:33bc88c4ab31 | 12 | delete(_filter); |
| rvt | 0:33bc88c4ab31 | 13 | } |
| rvt | 0:33bc88c4ab31 | 14 | |
| rvt | 0:33bc88c4ab31 | 15 | long AnalogInFiltered::getValue() { |
| rvt | 0:33bc88c4ab31 | 16 | return _filter->getData(); |
| rvt | 0:33bc88c4ab31 | 17 | } |
| rvt | 0:33bc88c4ab31 | 18 | |
| rvt | 0:33bc88c4ab31 | 19 | void AnalogInFiltered::measure () { |
| rvt | 0:33bc88c4ab31 | 20 | _filter->setData(_ain->read_u16() - 32768); |
| rvt | 0:33bc88c4ab31 | 21 | } |
| rvt | 0:33bc88c4ab31 | 22 | |
| rvt | 0:33bc88c4ab31 | 23 | |
| rvt | 0:33bc88c4ab31 | 24 | bool AnalogInFiltered::getIsChanged(int offSet) { |
| rvt | 0:33bc88c4ab31 | 25 | _filter->setData(_ain->read_u16() - 32768); |
| rvt | 0:33bc88c4ab31 | 26 | if (abs(_filter->getData() - _lastValue) > offSet) { |
| rvt | 0:33bc88c4ab31 | 27 | _lastValue = _filter->getData(); |
| rvt | 0:33bc88c4ab31 | 28 | return true; |
| rvt | 0:33bc88c4ab31 | 29 | } |
| rvt | 0:33bc88c4ab31 | 30 | return false; |
| rvt | 0:33bc88c4ab31 | 31 | } |
| rvt | 0:33bc88c4ab31 | 32 |
