From 6034b19f317b8581f474d0ad11544f2cbf247b68 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 13 Nov 2024 22:50:22 +0100 Subject: [PATCH] created basic main file for reading output from geiger counter it converts the values to CPM --- RadiationMapper.ino | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 RadiationMapper.ino diff --git a/RadiationMapper.ino b/RadiationMapper.ino new file mode 100644 index 0000000..b30d3f9 --- /dev/null +++ b/RadiationMapper.ino @@ -0,0 +1,50 @@ +#define INPUT_PIN D6 //VIN PIN FOR GEIGER COUNTER +#define MEASUREMENT_TIME_MS 60000 //MINUTE +#define MAX_CPM 5000 //HOW MANY COUNTS TO STORE + +unsigned long counts[MAX_CPM]; +int last_index = -1; + +//CALLBACK WHEN RADIATION PARTICLE IS DETECTED +void IRAM_ATTR increment_counts() +{ + counts[(++last_index) % MAX_CPM] = millis(); +} + +void setup() +{ + //INIT counts + for (int i = 0; i < MAX_CPM; i++) counts[i] = 0; + + Serial.begin(9600); + + //INIT PINS + pinMode(INPUT_PIN, INPUT); + attachInterrupt(digitalPinToInterrupt(INPUT_PIN), cb, FALLING); +} + +int last_counts = -1; +void loop() +{ + unsigned long current_millis = millis(); + int current_counts = 0; + + //COUNT + for (int i = 0; i < MAX_CPM; i++) + { + if (counts[i] == 0) continue; + if (current_millis - counts[i] >= MEASUREMENT_TIME_MS) //REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS + { + counts[i] = 0; + continue; + } + + current_counts++; //COUNT RECENT + } + + if (last_counts != current_counts) //PRINT CPM IF CHANGED + { + last_counts = current_counts; + Serial.println(String(current_counts) + " CPM"); + } +}