模擬#

介紹#

類比裝置讀取來自傳統VEX 3引腳類比感測器的連續電壓訊號,使EXP Brain能夠測量一系列值,而不是像DigitalIn那樣測量高或低狀態。

例如,感測器包括:

本頁面使用 analog_a 作為模擬設備的範例名稱。請根據需要將其替換為您自己配置的名稱。

以下是可用方法清單:

  • value – 傳回模擬設備的值。

  • changed – 註冊一個函數,當模擬設備的值發生變化時,該函數將被呼叫。

建構函式 – 手動初始化和配置模擬設備。

  • AnalogIn – 建立一個類比設備。

價值#

value 返回表示來自不同感測器的電壓訊號的類比設備的值。

Usage:
analog_a.value(units)

範圍

描述

units

Optional. The units to represent the value:

  • PERCENT
  • AnalogUnits.EIGHTBIT – Measure in an 8-bit analog value.
  • AnalogUnits.TENBIT – Measure in a 10-bit analog value.
  • AnalogUnits.TWELVEBIT (default) – Measure in a 12-bit analog value.

已更改#

changed 註冊一個函數,當模擬設備的值改變時,函數將會被呼叫。

Usage:
analog_a.changed(callback, arg)

參數

描述

callback

先前定義的 函數,當模擬設備的值改變時執行。

arg

可選。一個包含要傳遞給回呼函數的參數的tuple。有關更多信息,請參閱帶參數的函數。

def my_function():
  brain.screen.print("Changed")

# Call my_function whenever analog_a's value changes
analog_a.changed(my_function)

建構函數#

建構函數用於建立 Analog 對象,這些對像是配置模擬設備所必需的。

AnalogIn#

AnalogIn 建立一個模擬設備。

Usage:
AnalogIn(port)

範圍

描述

port

The 3-Wire Port that the analog device is connected to:

  • On the EXP Brain – brain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expander – expander.a where expander is the name of the expander instance.

# Create an analog device in Port A
analog_a = AnalogIn(brain.three_wire_port.a)