const int N = 8;
const float SIGMA = 0.4;
const float K = 3.0;
float riwayat[N];
int terisi = 0;
int pos = 0;
bool janggal(float x, float sigma, float k) {
bool hasil = false;
if (terisi == N) {
float jumlah = 0;
for (int i = 0; i < N; i++) {
jumlah += riwayat[i];
}
float rataRata = jumlah / N;
float selisih = x - rataRata;
if (fabs(selisih) > k * sigma) {
hasil = true;
}
}
riwayat[pos] = x;
pos = (pos + 1) % N;
if (terisi < N) {
terisi++;
}
return hasil;
}
float contoh[11] = {27.8, 28.0, 28.2, 27.9, 28.1, 28.0, 27.9, 28.1, 29.5, 28.1, 26.5};
void setup() {
Serial.begin(115200);
delay(1000);
for (int i = 0; i < 11; i++) {
Serial.printf("Bacaan %d: %.1f C -> ", i + 1, contoh[i]);
if (terisi < N) {
Serial.print("riwayat belum penuh, ");
}
if (janggal(contoh[i], SIGMA, K)) {
Serial.println("JANGGAL");
} else {
Serial.println("normal");
}
}
}
void loop() {
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4