光感應器#

介紹#

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

VEX EXP 光感測器。

類別建構函數#

light(
  triport::port &port );

類別析構函數#

摧毀 light 物件並釋放相關資源。

virtual ~light();

參數#

範圍

類型

描述

port

triport::port &

光感測器連接的 3 線端口,寫成 Brain.ThreeWirePort.X 或 ExpanderName.X,其中 X 是端口字母(例如, Brain.ThreeWirePort.A 或 Expander1.A)。

範例#

// 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 Functions
int32_t brightness(
  percentUnits units = percentUnits::pct );

Parameters

範圍

類型

描述

units

percentUnits

亮度單位: percent / pct (預設)—%

Return Values

傳回一個 int32_t ,表示光感測器測量的亮度,以百分比表示,範圍為 0 - 100%。

Examples
// 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);