Bonsoir à tous,
En adaptant légèrement le projet de cette page là : Davis Anemometer Arduino Hookup | Code (Part 2 of 3)
J'ai réussi à lire mon anémo de la marque Davis
Voici le code
#include <math.h>
#define WindSensorPin (0) // The pin location of the anemometer sensor
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
float WindSpeed; // speed miles per hour
void setup() {
Serial.begin(9600);
pinMode(WindSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
Serial.println("Davis Wind Speed Test");
Serial.println("Rotations\tMPH");
}
void loop() {
Rotations = 0; // Set Rotations count to 0 ready for calculations
//sei(); // Enables interrupts
delay (3000); // Wait 3 seconds to average
//cli(); // Disable interrupts
// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/3) = P * 0.75
WindSpeed = Rotations * 0.75;
Serial.print(Rotations); Serial.print("\t\t");
Serial.println(WindSpeed);
}
// This is the function that the interrupt calls to increment the rotation count
void isr_rotation () {
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
Rotations++;
ContactBounceTime = millis();
}
}
1ère remarque, le MKR1200 ne peut pas avoir d'interruptions sur la pin 2, je suis donc passé sur la Pin (0).
Deuxième remarque, j'ai du commenter les deux lignes Sei() et cli(); Et en faisant comme ça, ça marche.
Et là du coup, je comprends pas pourquoi ça marche et pourquoi on ne doit pas activer, puis désactiver les interruptions. C'est normal ?
Merci d'avance pour vos lumières