ユーザ用ツール

サイト用ツール


ja-jp_commands:reference:analogreadavg

analogReadAvg()

analogReadAvg()は複数の入力値の整数平均を返します。

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/analogreadavg.txt · 最終更新: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki