void onTick()
{
if (Count == 0) {
StartTime = micros();
}
Count++;
if (Count == 128) { // 取樣次數
unsigned long Sumtime = micros() - StartTime;
Count = 0;
if (Sumtime < 10000){ // 防止前次干擾
unsigned long fq = ((1000000 * 128 / Sumtime));
Serial.print(fq);
Serial.print(" Hz Time = ");
Serial.print(Sumtime);
Serial.println(" us");
}
}
}
接收端結果:
....
100000 Hz Time = 1280 us
100313 Hz Time = 1276 us
100313 Hz Time = 1276 us
100628 Hz Time = 1272 us
100628 Hz Time = 1272 us
32000 Hz Time = 4000 us
33057 Hz Time = 3872 us
34042 Hz Time = 3760 us