光感應器#
介紹#
light 類與光感測器配合使用,光感測器用於測量物體反射或照射到物體上的光的亮度。它輸出一個類比值,表示偵測到的光量。

類別建構函數#
light(
triport::port &port );
類別析構函數#
摧毀 light 物件並釋放相關資源。
virtual ~light();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
光感測器連接的 3 線端口,寫成 |
範例#
// Create a light instance in Port A
light LightA = light(Brain.ThreeWirePort.A);
成員功能#
light 類別包含以下成員函數:
brightness— 返迴光感測器偵測到的光量。
在呼叫任何 light 成員函數之前,必須先建立一個 light 實例,如下所示:
/* This constructor is required when using VS Code.
Light Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a light instance in Port A
light LightA = light(Brain.ThreeWirePort.A);
brightness#
返迴光感測器偵測到的光量。這可用於檢查物體是否足夠明亮,以便準確地報告其他視覺數據。
Available Functionsint32_t brightness(
percentUnits units = percentUnits::pct );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
亮度單位: |
傳回一個 int32_t ,表示光感測器測量的亮度,以百分比表示,範圍為 0 - 100%。
// Get Light Sensor brightness in range of 0% - 100%.
int32_t value = LightA.brightness();
// Print the brightness of the Light Sensor to the
// Brain's screen.
Brain.Screen.print(value);