-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRichUNOKnob.h
37 lines (29 loc) · 1.06 KB
/
RichUNOKnob.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef __RichUNO_KNOB_H__
#define __RichUNO_KNOB_H__
#include <Arduino.h>
#define FULL_ANGLE 280//full value of the rotary angle is 280 degrees
class Knob{
private:
int _pin;
public:
Knob(int pin)
{
_pin = pin;
pinMode(_pin, INPUT);
}
/********************************************************************************/
/*Function: Get the angle between the mark on the potentiometer cap and the starting position */
/*Parameter:-void */
/*Return: -int,the range of degrees is 0~280 */
inline int getAngle()
{
int sensor_value = analogRead(_pin);
int angle;
angle = map(sensor_value, 0, 1023, 0, 280);
return angle;
}
};
#endif
/*********************************************************************************************************
END FILE
*********************************************************************************************************/