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@2:ae7a31a3c618, 2013-08-30 (annotated)
- Committer:
- rvt
- Date:
- Fri Aug 30 01:37:49 2013 +0000
- Revision:
- 2:ae7a31a3c618
- Parent:
- 0:33bc88c4ab31
- Child:
- 5:a0bb17c379ce
Better PushButton handling
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 | 2:ae7a31a3c618 | 4 | AnalogInFiltered::AnalogInFiltered(AnalogFilterInterface *filter, PinName pin, int fuzzyFactor) { |
| rvt | 0:33bc88c4ab31 | 5 | _ain = new AnalogIn(pin); |
| rvt | 0:33bc88c4ab31 | 6 | _filter = filter; |
| rvt | 2:ae7a31a3c618 | 7 | _fuzzyFactor = fuzzyFactor; |
| rvt | 0:33bc88c4ab31 | 8 | _lastValue=0; |
| rvt | 0:33bc88c4ab31 | 9 | } |
| rvt | 0:33bc88c4ab31 | 10 | |
| rvt | 0:33bc88c4ab31 | 11 | AnalogInFiltered::~AnalogInFiltered() { |
| rvt | 0:33bc88c4ab31 | 12 | delete(_ain); |
| rvt | 0:33bc88c4ab31 | 13 | delete(_filter); |
| rvt | 0:33bc88c4ab31 | 14 | } |
| rvt | 0:33bc88c4ab31 | 15 | |
| rvt | 0:33bc88c4ab31 | 16 | void AnalogInFiltered::measure () { |
| rvt | 0:33bc88c4ab31 | 17 | _filter->setData(_ain->read_u16() - 32768); |
| rvt | 0:33bc88c4ab31 | 18 | } |
| rvt | 0:33bc88c4ab31 | 19 | |
| rvt | 2:ae7a31a3c618 | 20 | long AnalogInFiltered::getData() { |
| rvt | 2:ae7a31a3c618 | 21 | return _filter->getData(); |
| rvt | 2:ae7a31a3c618 | 22 | } |
| rvt | 0:33bc88c4ab31 | 23 | |
| rvt | 2:ae7a31a3c618 | 24 | |
| rvt | 2:ae7a31a3c618 | 25 | bool AnalogInFiltered::getIsChanged() { |
| rvt | 2:ae7a31a3c618 | 26 | // _filter->setData(_ain->read_u16() - 32768); |
| rvt | 2:ae7a31a3c618 | 27 | if (abs(_filter->getData() - _lastValue) > _fuzzyFactor) { |
| rvt | 0:33bc88c4ab31 | 28 | _lastValue = _filter->getData(); |
| rvt | 0:33bc88c4ab31 | 29 | return true; |
| rvt | 0:33bc88c4ab31 | 30 | } |
| rvt | 0:33bc88c4ab31 | 31 | return false; |
| rvt | 0:33bc88c4ab31 | 32 | } |
| rvt | 0:33bc88c4ab31 | 33 | |
| rvt | 2:ae7a31a3c618 | 34 | int AnalogInFiltered::getFuzzyFactor() { |
| rvt | 2:ae7a31a3c618 | 35 | return _fuzzyFactor; |
| rvt | 2:ae7a31a3c618 | 36 | } |
