あなたは++peakcounter
を使用してpeakcounterをインクリメントが、その後はすぐにif(peakcounter==0)
の場合はブロックでpeakcounter=0
を設定し、あなたがするために必要なもの2
if (valstate == false && Pdelta >= average)
{
{
++peakcounter; // keeps the count of how many times the value has gone
above average
}
// Checks for the number of times and then performs action
if (peakcounter == 1) {
digitalWrite(4, HIGH);
startTime = millis();
valstate = true;
peakcounter = 0; //the offending line
}
peakcounterの==に取得することはありません次の操作を行います(注:コードは最適化されていません。必要なものは完全には理解できませんが、これで問題は解決します)
int currentMax = 0;
// your code here....
if (valstate == false && Pdelta >= average){
++peakcounter;
if(peakcounter > currentMax){
// Checks for the number of times and then performs action
if (peakcounter == 1) {
digitalWrite(4, HIGH);
startTime = millis();
valstate = true;
peakcounter = 0;
currentMax++;
}
//the rest of your peakcount checking code here
}
スイッチケースを使用する例を提供することができます – Naley