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: BSP_DISCO_F746NG Graphics mbed
Diff: HardwareAccess/Angle.cpp
- Revision:
- 0:8acbce46eede
- Child:
- 1:4a5e329e617b
diff -r 000000000000 -r 8acbce46eede HardwareAccess/Angle.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HardwareAccess/Angle.cpp Sun Nov 06 02:14:34 2016 +0000
@@ -0,0 +1,47 @@
+//
+// Angle.cpp
+//
+
+#include "mbed.h" // for AnalogIn
+#include "Angle.h"
+
+#ifdef ARDUINO
+int anglePin = 0;
+#else
+AnalogIn angleRead(A0);
+#endif
+
+Angle::Angle()
+{
+ angle = 0;
+ direction = Left;
+ delta = 1.0f;
+}
+
+float Angle::GetAngle()
+{
+ if(direction == Left) {
+ angle += delta;
+ if(angle > FULL_ANGLE) {
+ angle -= FULL_ANGLE;
+ }
+ } else { // Right
+ angle -= delta;
+ if(angle < 0) {
+ angle += FULL_ANGLE;
+ }
+ }
+ return angle;
+}
+
+/// Read the rotation angle from a potentiometer attached to pin A0
+float Angle::ReadAngle()
+{
+#ifdef ARDUINO
+ angle = analogRead(anglePin);
+#else
+ angle = angleRead;
+#endif
+
+ return angle/1024.f * FULL_ANGLE;
+}
\ No newline at end of file