IanalogFilter()は渡された値を移動平均処理します。
int32_t IanalogFilter(uint8_t id, int32_t raw_value, uint8_t samples)
| コマンド | 引数 | 戻り値 | 動作 |
|---|---|---|---|
IanalogFilter(id, raw_value, samples) | uint8_t id — フィルタ識別番号int32_t raw_value — 新しい入力値uint8_t samples — 平均サンプル数 | int32_t | 渡された値を移動平均処理します。 |
void setup() { Serial.begin(115200); analogReadInit(IANALOG_SPS_128); // アナログ入力モジュールのサンプリング速度を設定します。 } void loop() { const int32_t raw = analogRead(A0); // 指定チャンネルの生のアナログ値を読み取ります。 const int32_t filtered = IanalogFilter(0, raw, 10); // 渡された値を移動平均で処理します。 static int32_t previous = 0; if (abs(filtered - previous) >= 5) { previous = filtered; Serial.println(filtered); } }
A0とMPAINOの0は物理的な意味が異なるため、製品群を変更するときは引数を再確認してください。