Created
April 18, 2017 19:39
-
-
Save anonymous/2c0814fdb82f5e8bc516285a7d25668a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_PCD8544.h> | |
#define LOG_PERIOD 15000 //Logging period in milliseconds, recommended value 15000-60000. | |
#define MAX_PERIOD 60000 //Maximum logging period without modifying this sketch | |
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); | |
unsigned long counts; //variable for GM Tube events | |
float cpm; //variable for CPM | |
unsigned long multiplier; //variable for calculation CPM in this sketch | |
unsigned long previousMillis; //variable for time measurement | |
float MSVh; | |
float MR; | |
void tube_impulse(){ //subprocedure for capturing events from Geiger Kit | |
counts++; | |
} | |
void setup() | |
{ | |
Serial.begin(9600); | |
display.begin(); | |
display.setContrast(61); | |
display.setRotation(2); | |
display.clearDisplay(); | |
counts = 0; | |
cpm = 0; | |
multiplier = MAX_PERIOD / LOG_PERIOD; //calculating multiplier, depend on your log period | |
Serial.begin(9600); | |
attachInterrupt(0, tube_impulse, FALLING); //define external interrupts | |
} | |
void loop() { | |
unsigned long currentMillis = millis(); | |
if(currentMillis - previousMillis > LOG_PERIOD){ | |
previousMillis = currentMillis; | |
cpm = counts * multiplier; | |
MSVh = cpm/151; | |
MR = MSVh * 100; | |
Serial.print(cpm); | |
display.setTextSize(1); | |
display.setTextColor(BLACK); | |
display.setCursor(10,0); | |
display.println(MSVh); | |
display.setCursor(5,20); | |
display.println("mSv/h"); | |
display.setCursor(50,0); | |
display.println(MR); | |
display.setCursor(60,20); | |
display.println("mRh"); | |
display.display(); | |
display.clearDisplay(); | |
counts = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment