アナログ入力#

導入#

analog_in クラスは、VEX V5 3線式ポートに接続されたデバイスからのアナログ入力信号を読み取るために使用されます。このクラスは、現在のアナログ値へのアクセスを提供し、値の変更に対するコールバック関数を登録できるようにします。

クラスコンストラクタ#

analog_in(
    triport::port &port );

クラスデストラクタ#

analog_in オブジェクトを破棄し、関連するリソースを解放します。

~analog_in();

パラメータ#

パラメータ

タイプ

説明

port

triport::port&

アナログ入力が接続されている 3 線ポートは、 Brain.ThreeWirePort.X または ExpanderName.Xのように記述され、 X はポート文字です (たとえば、 Brain.ThreeWirePort.A または Expander1.A)。

例#

// Create the analog_in instance on 3-Wire Port A
analog_in AnalogInA = analog_in(Brain.ThreeWirePort.A);

メンバーの機能#

analog_in クラスには、以下のメンバ関数が含まれています。

  • value — アナログ入力デバイスの値を返します。

  • changed — アナログ入力値が変化したときのコールバック関数を登録します。

analog_in メンバ関数を呼び出す前に、以下に示すように analog_in インスタンスを作成する必要があります。

/* This constructor is required to use an
Analog Input device. Replace the values
as needed. */

// Create the analog_in instance on 3-Wire Port A
analog_in AnalogInA = analog_in(Brain.ThreeWirePort.A);

value#

アナログ入力の現在の値を返します。

Available Functions
int32_t value(
  analogUnits units );

Parameters

パラメータ

タイプ

説明

units

analogUnits

値を表す単位:

  • range8bit — 8ビットアナログ値 (256の状態を持つ値)
  • range10bit — 10ビットアナログ値 (1024の状態を持つ値)
  • range12bit — 12ビットアナログ値 (4096の状態を持つ値)
  • pct — パーセンテージ
  • mV — ミリボルト

Return Values

この関数は、アナログ入力の現在の値を返します。

Examples
// Get the current value of the Analog Input
int32_t value = AnalogInA.value();

changed#

アナログ入力の値が変化したときに呼び出されるコールバック関数を登録します。

Available Functions
void changed( void (* callback)(void) );

Parameters

パラメータ

タイプ

説明

callback

void (* callback)(void)

アナログ入力の値が変化したときに呼び出される関数。

Return Values

この関数は値を返しません。

Examples

コールバック関数を定義します( int main()の外側)

// Display a message when the input changes
void AnalogInputChanged() {
  Brain.Screen.print("analog input changed");
}

コールバックを登録する int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run AnalogInputChanged when the value of the
  // Analog Input changes
  AnalogInA.changed(AnalogInputChanged);
}