Skip to content

Instantly share code, notes, and snippets.

@sergiomtzlosa
Last active May 20, 2020 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sergiomtzlosa/94991fac13dcedee2f40162e8a5c8930 to your computer and use it in GitHub Desktop.
Save sergiomtzlosa/94991fac13dcedee2f40162e8a5c8930 to your computer and use it in GitHub Desktop.
/**
*
* 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