101020048-Grove-Rotary_Angle_Sensor.md
7/25/2019
Grove - Rotary Angle Sensor SKU: 101020048
tags: grove_analog, io_3v3, io_5v, plat_duino, plat_linkit, plat_bbg,
plat_wio
电½计在其
D1
连接器上产生
0
和
Vcc
之间的模拟输出
( 5V
直流,½用Seeeduino)。D2 连接器未½用。角度
范围为
300
度,具有线性变化的特性。电阻值为
10
欧姆,非常适合
Arduino
½用。这也可以称为旋½角度传
感器。
还有另一个产品
-
Grove - Rotary Angle Sensor(P)。
"P"
是什么意思?
"P"
是本产品中的“面板安装”。它是
Grove
- Rotary Angle Sensor
的姐妹版本。 它们是相同的,除了
Grove
连接器被移动到后面,这样可以便您可以½松
地将其用½一个整洁的无线人机界面设备。
1/8
101020048-Grove-Rotary_Angle_Sensor.md
7/25/2019
产品特性
Grove
接口
易于½用
Grove Base
模块
!!!Tip
关于
Grove
模块的更多信息请点击
Grove System
规格参数
4.75
0
5.0
~
5.25
300
19x19x30.1
Platforms Supported
½用方法
与
Arduino
一起½用
以下草图演示了½用旋½角度传感器控制
LED
亮度的简单应用。旋½角度传感器的角度为
0~300
度,为了控
制
LED
的亮度,我们应该在演示代码中½换为相应的电压值。
如下图所示,旋½角传感器传感器连接到
Grove - Base Shield
的模拟端口
A0,LED
连接到数字端口
2。
2/8
½单
VDC
Deg
mm
值大最
值型典
值小最
寸尺
度角½旋
压电
目项
101020048-Grove-Rotary_Angle_Sensor.md
7/25/2019
将下面的代码复制并粘贴到新的
Arduino
文件上。
/******************************************************************************/
/*macro definitions of Rotary angle sensor and LED pin*/
#define ROTARY_ANGLE_SENSOR A0
#define LED 2//the Grove - LED is connected to D3 of Arduino
#define ADC_REF 5//reference voltage of ADC is 5v.If the Vcc switch on the
seeeduino
//board switches to 3V3, the ADC_REF should be 3.3
#define GROVE_VCC 5//VCC of the grove interface is normally 5v
#define FULL_ANGLE 300//full value of the rotary angle is 300 degrees
void setup()
{
Serial.begin(9600);
pinsInit();
}
void loop()
{
int degrees;
degrees = getDegree();
Serial.println("The angle between the mark and the starting position:");
Serial.println(degrees);
3/8
101020048-Grove-Rotary_Angle_Sensor.md
7/25/2019
int brightness;
/*The degrees is 0~300, should be converted to be 0~255 to control the*/
/*brightness of LED
*/
brightness = map(degrees, 0, FULL_ANGLE, 0, 255);
controlBrightness(brightness);
delay(500);
}
void pinsInit()
{
pinMode(ROTARY_ANGLE_SENSOR, INPUT);
pinMode(LED,OUTPUT);
}
/*PWM control brightness
*/
/*If brightness is 0,the LED is off.
*/
/*The Greater the brightness, the brighter the LED.*/
/*The range of brightness is 0~255
*/
void controlBrightness(int brightness)
{
analogWrite(LED,brightness);
}
/************************************************************************/
/*Function: Get the angle between the mark and the starting position
*/
/*Parameter:-void
*/
/*Return:
-int,the range of degrees is 0~300
*/
int getDegree()
{
int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
float voltage;
voltage = (float)sensor_value*ADC_REF/1023;
float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
return degrees;
}
上传代码。
然后您就可以通过旋½传感器来控制
LED
了。试试吧!
与
TI LaunchPad
一起½用
器感传度角½旋 器½电取读
(
)
此示例显示如½读取来自
Grove
电½器模块的模拟输出。我们将在这个例子中组合几个
Grove
模块!通过旋½
电½器旋钮,我们将在
Grove 4
数字显示屏上显示模拟读数值。
4/8
101020048-Grove-Rotary_Angle_Sensor.md
7/25/2019
/*
Rotary Angle Sensor
Demonstrates analog input by reading an analog sensor on J16 of the Grove
Base BoosterPack. The speed of the red LED on the LaunchPad will change depending
on the position of the potentiometer knob. This example will also display the
analog reading value on the Grove 4-digital display.
The circuit:
* Potentiometer attached to pin 24 (J6 on Grove Base BoosterPack)
* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to VCC (3.3V)
* Note: Because of unstable of the voltage, the value of the rotary angle
sensor
varies slightly from run to run even you don't touch it.
Created by Oliver Wang
This example code is in the public domain.
http://www.seeedstudio.com/wiki/GROVE_-_Starter_Kit_v1.1b#Grove_-
_Rotary_Angle_Sensor
*/
#include "TM1637.h"
/* Macro Define */
#define CLK
*/
5/8
39
/* 4-digital display clock pin