====== analogReadAvg() ====== ''analogReadAvg()''は複数の入力値の整数平均を返します。 {{:ja-jp_commands:reference:analogreadavg.svg?900|analogReadAvg コマンドの動作フロー}} ''int32_t analogReadAvg(uint8_t ch, uint8_t samples)'' ===== コマンド ===== ^ コマンド ^ 引数 ^ 戻り値 ^ 動作 ^ | ''analogReadAvg(ch, samples)'' | ''uint8_t ch''\\ ''uint8_t samples'' — 平均サンプル数 | ''int32_t'' | 複数の入力値の整数平均を返します。 | ===== 使用例 ===== void setup() { Serial.begin(115200); } void loop() { int ai0 = analogRead(0); // 指定チャンネルの生のアナログ値を読み取ります。 int ai4 = analogRead(4); // 指定チャンネルの生のアナログ値を読み取ります。 int32_t avg0 = analogReadAvg(0, 5); // 複数の入力値の整数平均を返します。 float avg0f = analogReadAvgf(0, 5); // 複数の入力値の浮動小数点平均を返します。 Serial.print("AI0: "); Serial.println(ai0); Serial.print("AI4: "); Serial.println(ai4); Serial.print("AI0 AVG: "); Serial.println(avg0); Serial.print("AI0 AVG float: "); Serial.println(avg0f, 2); delay(500); } ===== 注意事項 ===== * 製品ごとの対応チャネルとモジュールDIPスイッチの入力範囲を先に確認します。 * エラー定数を正常な測定値として使用しないでください。 * サンプル数を増やすと応答が遅くなり、メモリ使用量が増加します。 * MPINOの''A0''とMPAINOの''0''は物理的な意味が異なるため、製品群を変更するときは引数を再確認してください。 ===== 同じカテゴリの内蔵コマンド ===== * [[:ja-jp_commands:reference:analogreadinit|analogReadInit() 詳細説明を見る]] * [[:ja-jp_commands:reference:analogread|analogRead() 詳細説明を見る]] * [[:ja-jp_commands:reference:analogreadavgf|analogReadAvgf() 詳細説明を見る]] [[:ja-jp_commands:builtin|← 内蔵コマンド一覧]]