GM Tube Signal Detection Code

//Counting falling edges
volatile int count = 0;       
//Counter for 1 minute
uint32_t start = millis(); 

void setup() {
 //Setup serial communication for debugging
  Serial.begin(9600);     
  Serial.print("Start");
  
  //Input pin for signal line
  pinMode(2, INPUT);

  // Attach interrupt on pin 2 for signal detection
  attachInterrupt(digitalPinToInterrupt(2), handleInterrupt, FALLING);
}

void loop() {
  //Check if 1 second has passed
  if (millis() - start >= 60000) {
    Serial.print("Counts per minute: ");
    Serial.println(count);     

    //Reset count and start time for the next minute
    count = 0;                   
    start = millis();              
  }
}

//Interrupt Service Routine 
void handleInterrupt() {
   //Increment number of signals detected
  count++; 
}

Copyright © 2024 Richard Loong

Page last modified: 16 Nov 2024.