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
Diff: AnalogInFiltered.cpp
- Revision:
- 0:33bc88c4ab31
- Child:
- 2:ae7a31a3c618
diff -r 000000000000 -r 33bc88c4ab31 AnalogInFiltered.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/AnalogInFiltered.cpp Wed Aug 28 02:33:03 2013 +0000
@@ -0,0 +1,32 @@
+#include "AnalogInFiltered.h"
+
+
+AnalogInFiltered::AnalogInFiltered(AnalogFilterInterface *filter, PinName pin) {
+ _ain = new AnalogIn(pin);
+ _filter = filter;
+ _lastValue=0;
+}
+
+AnalogInFiltered::~AnalogInFiltered() {
+ delete(_ain);
+ delete(_filter);
+}
+
+long AnalogInFiltered::getValue() {
+ return _filter->getData();
+}
+
+void AnalogInFiltered::measure () {
+ _filter->setData(_ain->read_u16() - 32768);
+}
+
+
+bool AnalogInFiltered::getIsChanged(int offSet) {
+ _filter->setData(_ain->read_u16() - 32768);
+ if (abs(_filter->getData() - _lastValue) > offSet) {
+ _lastValue = _filter->getData();
+ return true;
+ }
+ return false;
+}
+
