- int signal;
- static int total_samples = 0;
- static int high_samples = 0;
-
- // read from the WWVB receiver, with some hysteresis
- if (total_samples >= 100) {
- if (high_samples > 20) {
- signal = HIGH;
- }
- else {
- signal = LOW;
- }
- total_samples = 0;
- high_samples = 0;
- }
- else {
- total_samples += 1;
- if (digitalRead(wwvb) == HIGH) {
- ++high_samples;
- }
- }
+
+ // Reading it three times and taking the average gives us some hysteresis
+ int signal = (digitalRead(wwvb) + digitalRead(wwvb) + digitalRead(wwvb)) / 3;