Skip to content

Instantly share code, notes, and snippets.

@RobCranfill
Created October 9, 2024 00:49
Show Gist options
  • Save RobCranfill/961db6908d441b51dbfa0978b003ff1a to your computer and use it in GitHub Desktop.
Save RobCranfill/961db6908d441b51dbfa0978b003ff1a to your computer and use it in GitHub Desktop.
Test of new anemometer hardware with Feather RP2040 and Arduino code
// Based on https://how2electronics.com/interfacing-anemometer-npn-pulse-output-with-arduino/
unsigned long DEBOUNCE_DELAY = 1000; // the debounce time; increase if the output flickers
int PIN_INTERRUPT = 25;
unsigned long lastDebounceTime_ = 0; // the last time the output pin was toggled
int count_ = 0;
int iter_ = 0;
void onChange()
{
if (digitalRead(PIN_INTERRUPT) == LOW)
count_++;
}
void setup()
{
Serial.begin(115200); // Initialize serial port
Serial.println("Hello, Cran!");
pinMode(PIN_INTERRUPT, INPUT_PULLUP); // set the interrupt pin
// Enable interrupt
attachInterrupt(digitalPinToInterrupt(PIN_INTERRUPT), onChange, FALLING);
}
void loop()
{
if ((millis() - lastDebounceTime_) > DEBOUNCE_DELAY)
{
lastDebounceTime_ = millis();
iter_++;
// for console:
// Serial.print(iter_);
// Serial.print(": ");
// Serial.print((count_ * 8.75)/100);
// Serial.println(" m/s");
// for plotter:
Serial.print("Wind_Speed:");
Serial.println((count_ * 8.75)/100);
count_ = 0;
}
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment