Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
*
* Pin D2 -> Arduino Interruption
* Pin D7 -> Buzzer
* Pin D8 -> Led
* Pin D9 -> External Interruption to connect other Arduino/Raspberry
*
*/
#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;
const int buzzerPin = 7;
const int ledPin = 8;
const int interruptionPin = 9;
void ISR_impulse() { // Captures count of events from Geiger counter board
counts++;
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
digitalWrite(interruptionPin, HIGH);
Serial.println("click");
}
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(interruptionPin, OUTPUT);
pinMode(inputPin, INPUT_PULLUP);
delayMicroseconds(50);
EIFR |= (1 << INTF1); // Enable interrupts on Arduino Nano
attachInterrupt(digitalPinToInterrupt(inputPin), ISR_impulse, RISING);
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
digitalWrite(interruptionPin, LOW);
}
void loop() {
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
digitalWrite(interruptionPin, LOW);
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.