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
HardwareAccess/Angle.cpp
- Committer:
- karpent
- Date:
- 2016-11-06
- Revision:
- 0:8acbce46eede
- Child:
- 1:4a5e329e617b
File content as of revision 0:8acbce46eede:
//
// 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;
}