Skip to content

Instantly share code, notes, and snippets.

@sergiomtzlosa
Last active May 20, 2020 12:47
Show Gist options
  • Save sergiomtzlosa/8ad0ea9920b63b9117411b67fe2ed000 to your computer and use it in GitHub Desktop.
Save sergiomtzlosa/8ad0ea9920b63b9117411b67fe2ed000 to your computer and use it in GitHub Desktop.
#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