Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#define LOG_PERIOD 20000 //Logging period in milliseconds
#define MINUTE_PERIOD 60000
volatile unsigned long counts = 0; // Tube events
unsigned long cpm = 0; // CPM
unsigned long previousMillis; // Time measurement
const int inputPin = 2;
void ISR_impulse() { // Captures count of events from Geiger counter board
counts++;
Serial.println("click");
}
void setup() {
Serial.begin(9600);
pinMode(inputPin, INPUT);
interrupts();
attachInterrupt(digitalPinToInterrupt(inputPin), ISR_impulse, RISING); // Define interrupt on falling edge
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > LOG_PERIOD) {
previousMillis = currentMillis;
cpm = counts * MINUTE_PERIOD / LOG_PERIOD;
Serial.println(String(cpm) + " cpm");
counts = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.