2024-11-14 18:36:04 +01:00
|
|
|
#include <list>
|
|
|
|
|
2024-11-13 22:50:22 +01:00
|
|
|
#define INPUT_PIN D6 //VIN PIN FOR GEIGER COUNTER
|
|
|
|
#define MEASUREMENT_TIME_MS 60000 //MINUTE
|
|
|
|
|
2024-11-14 18:36:04 +01:00
|
|
|
std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
|
2024-11-13 22:50:22 +01:00
|
|
|
|
|
|
|
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED
|
|
|
|
void IRAM_ATTR increment_counts()
|
|
|
|
{
|
2024-11-14 18:36:04 +01:00
|
|
|
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
|
2024-11-13 22:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2024-11-14 18:36:04 +01:00
|
|
|
//SERIAL COMMUNICATION INIT
|
2024-11-13 22:50:22 +01:00
|
|
|
Serial.begin(9600);
|
|
|
|
|
|
|
|
//INIT PINS
|
|
|
|
pinMode(INPUT_PIN, INPUT);
|
2024-11-14 17:58:16 +01:00
|
|
|
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING);
|
2024-11-13 22:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int last_counts = -1;
|
|
|
|
void loop()
|
|
|
|
{
|
2024-11-14 18:36:04 +01:00
|
|
|
unsigned long current_millis = millis(); //CURRENT TIME
|
2024-11-13 22:50:22 +01:00
|
|
|
int current_counts = 0;
|
|
|
|
|
2024-11-14 18:36:04 +01:00
|
|
|
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
|
|
|
|
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
|
2024-11-13 22:50:22 +01:00
|
|
|
{
|
2024-11-14 18:36:04 +01:00
|
|
|
return (current_millis - particle >= MEASUREMENT_TIME_MS);
|
|
|
|
});
|
|
|
|
|
|
|
|
//COUNT RECENT
|
|
|
|
current_counts = counts.size();
|
2024-11-13 22:50:22 +01:00
|
|
|
|
|
|
|
if (last_counts != current_counts) //PRINT CPM IF CHANGED
|
|
|
|
{
|
|
|
|
last_counts = current_counts;
|
|
|
|
Serial.println(String(current_counts) + " CPM");
|
|
|
|
}
|
|
|
|
}
|