ja-jp_commands:reference:itpl
文書の過去の版を表示しています。
Itpl()
Itpl()は(Pulse Timer)条件がONになった瞬間から設定時間の間trueを返します。
bool Itpl(uint8_t timer_id, bool state, unsigned long delayTime)
コマンド
| コマンド | 引数 | 戻り値 | 動作 |
|---|---|---|---|
Itpl(timer_id, state, delayTime) | uint8_t timer_id — タイマ番号。0 ~ 255の範囲で使用可能bool state — タイマ入力状態unsigned long delayTime — 設定時間。単位はms | bool | (Pulse Timer)条件がONになった瞬間から設定時間の間trueを返します。 |
使用例
MPINO-8A4R(T)-Sを選択した例です。入力P0と出力P32を使用し、loop()を止めずに毎回コマンドを呼び出します。 入力の立ち上がりで出力が1秒間ONになり、動作中の再入力で1秒を数え直します。
const uint8_t INPUT_PIN = 0; const uint8_t OUTPUT_PIN = 32; void setup() { pinMode(INPUT_PIN, INPUT); pinMode(OUTPUT_PIN, OUTPUT); } void loop() { const bool inputOn = digitalRead(INPUT_PIN) == HIGH; const bool outputOn = Itpl(0, inputOn, 1000); // 立ち上がりで1秒のパルスを作り、再入力時に時間を数え直します。 digitalWrite(OUTPUT_PIN, outputOn ? HIGH : LOW); }
注意事項
- 経過時間と入力OFFを処理するため、タイマコマンドを
loop()で繰り返し呼び出します。 - 異なるタイマ動作で同じ
timer_idを共有すると状態が混ざるため、別の番号を使用します。
同じカテゴリの内蔵コマンド
ja-jp_commands/reference/itpl.1789221300.txt.gz · 最終更新: by 127.0.0.1
