Oczywiście, nie ma sprawy.
Odczytuję impulsy za pomocą KLOPa (klop0 - tylko liczy impulsy, potem obliczenia robią KPOPy).
Jeśli coś nie jasne - proszę pytaj.
Sorry za kilkujęzyczne komentarze.
Code: Select all
nIC0_State = digitalRead(IC0_Pin); // odczyt stanu, wspólne GPIO
// Zmiana stanu Klop0 - tekuce brojaci, no history, no FRAM
if (millis() - ResetTime > LoopTime) { // co LoopTime
ResetTime = millis(); // reset timestamp
IC0_Tmp = nIC0_Val - oIC0_Val; // razlika impulsa
tIC0_Val[nCounter] = IC0_Tmp;
// 10min Average
IC0_10mVal = 0;
for (int i = 0; i < MeasCount; i++){
IC0_10mVal = IC0_10mVal + tIC0_Val[i];
// printf("\n\t index: %d \t tIC0_Val[i]: %d", i, tIC0_Val[i]);
}
IC0_10mAvg = IC0_10mVal * (float)1000 / MeasCount / LoopTime; // średnia krocząca in [LoopTime]
// Zmiana stanu Klop0 - imp. counter
if (nIC0_Val != oIC0_Val) { // flows
IC0_Tmp = nIC0_Val - oIC0_Val; // imp. difference
IC0_Avg = IC0_Tmp * (float)1000 / LoopTime; // imp. average in [LoopTime]
oIC0_Val = nIC0_Val; // oIC0_Val update
}
else { // nema vjetra/kise
IC0_Tmp = IC0_Avg = 0;
}
gpm4->setValue(IC0_Avg); // set new tmp Avg m/s value
gpm5->setValue(IC0_Avg); // set new tmp Avg km/h value
// printf("\n\nA:\t nCounter: %d \t IC0_Tmp: %f \t tIC0_Val[nCounter]: %d \n", nCounter, IC0_Tmp, tIC0_Val[nCounter]);
// printf("B:\t IC0_Tmp: \t\t%f \t IC0_Avg: \t%f \n", IC0_Tmp, IC0_Avg);
// printf("C:\t IC0_10mVal: \t%f \t IC0_10mAvg: \t%f \n", IC0_10mVal, IC0_10mAvg);
gpm6->setValue(IC0_10mAvg); // aktualizacja wartości 10m m/s
gpm7->setValue(IC0_10mAvg); // aktualizacja wartości 10m km/h
nCounter = nCounter + 1; // zwiększenie indeksu tablicy
if(nCounter == MeasCount){
nCounter = 0; // reset indeksu
}