電位器#
介紹#
pot 和 potV2 類與電位器配合使用,電位器是一種類比感測器,用於測量旋轉軸的角位置。電位器輸出的電壓與其位置成正比。
根據電位器型號的不同,其可偵測的旋轉量也不同:
電位器 - 最高可達 250 度
電位器 V2 - 330 度(連續)
|
|
|---|---|
電位器 |
電位器 V2 |
電位器#
Class Constructors#
pot(
triport::port &port );
Class Destructor#
銷毀 pot 物件並釋放相關資源。
~pot();
Parameters#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
電位器連接的 3 線端口,寫成 |
Example#
// Create a pot instance in Port A
pot PotentiometerA = pot(Brain.ThreeWirePort.A);
電位器 V2#
Class Constructors#
potV2(
triport::port &port );
Class Destructor#
銷毀 potV2 物件並釋放相關資源。
~potV2();
Parameters#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
電位器 V2 連接的 3 線端口,寫成 |
Examples#
// Create a Potentiometer V2 on 3-Wire Port A
potV2 PotentiometerV2A = potV2(Brain.ThreeWirePort.A);
成員功能#
pot 和 potV2 類別包含以下成員函數:
angle— 傳回電位器的角度位置(以度數或百分比表示)。
在呼叫任何 pot 或 potV2 成員函數之前,必須建立 pot 或 potV2 實例,如下所示:
/* This constructor is required when using VS Code.
Potentiometer configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a potV2 instance in Port A
potV2 PotentiometerV2A = potV2(Brain.ThreeWirePort.A);
angle#
返回電位器的角度位置。
1 — 此函數以百分比表示角度。
int32_t angle ( percentUnits units = percentUnits::pct );
Parameters2 — 此函數以選取的旋轉單位表示角度。
double angle( rotationUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
表示位置佔完整旋轉百分比的單位: |
|
|
表示角度的單位:
|
返回:
使用
percentUnits時,int32_t為 。當使用
double,rotationUnits。
// Get the current angle of the Potentiometer V2 in the
// range 0 to 330 degrees.
double angle = PotentiometerV2A.angle(degrees);
// Print the current angle of the Potentiometer to the
// brain screen.
Brain.Screen.print(angle);

