# 模拟电位器-软件¶

## AnalogPotentiometer 类¶

AnalogPotentiometer构造函数中的“全范围”或“范围”参数是从0-1的比例因子而不是从0-5的。也就是说，它们代表一个自然的小数位数，而不是电压等级。

// Initializes an AnalogPotentiometer on analog port 0
// The full range of motion (in meaningful external units) is 0-180 (this could be degrees, for instance)
// The "starting point" of the motion, i.e. where the mechanism is located when the potentiometer reads 0v, is 30.

AnalogPotentiometer pot = new AnalogPotentiometer(0, 180, 30);


### 自定义底层模拟输入¶

// Initializes an AnalogInput on port 0, and enables 2-bit averaging
input.setAverageBits(2);

// Initializes an AnalogPotentiometer with the given AnalogInput
// The full range of motion (in meaningful external units) is 0-180 (this could be degrees, for instance)
// The "starting point" of the motion, i.e. where the mechanism is located when the potentiometer reads 0v, is 30.

AnalogPotentiometer pot = new AnalogPotentiometer(input, 180, 30);


### 从模拟电位计读取值¶

pot.get();