Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions RadiationWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
#include "Arduino.h"
#include "RadiationWatch.h"

RadiationWatch::RadiationWatch(int signPin, int noisePin) : _signPin(signPin), _noisePin(noisePin)
int signCount; //Counter for Radiation Pulse

//Called via Interrupt when a radiation pulse is detected
void triggerRadiationPulse() {
signCount++;
tone(8, 800, 1); // Output classic geiger counter tick noise
}

RadiationWatch::RadiationWatch(int signPin, int noisePin, int signIRQ) : _signPin(signPin), _noisePin(noisePin), _signIRQ(signIRQ)
{
signCount = 0;
_prevTime = 0;
index = 0;

signCount = 0;
noiseCount = 0;

sON = 0;
Expand All @@ -38,6 +46,10 @@ void RadiationWatch::setup()
pinMode(_noisePin,INPUT);
digitalWrite(_noisePin,HIGH);

//Attach interrupt handler to catch incoming radiation pulses,
//and execute triggerRadiationPulse() when this happens.
attachInterrupt(_signIRQ, triggerRadiationPulse, FALLING);

//Initialize cpmHistory[]
for(int i = 0; i < kHistoryCount;i++ )
{
Expand All @@ -61,19 +73,9 @@ void RadiationWatch::loop()
{
// Raw data of Radiation Pulse: Not-detected -> High, Detected -> Low
int sign = signPin();

// Raw data of Noise Pulse: Not-detected -> Low, Detected -> High
int noise = noisePin();

//Radiation Pulse normally keeps low for about 100[usec]
if(sign==0 && sON==0)
{//Deactivate Radiation Pulse counting for a while
sON = 1;
signCount++;
}else if(sign==1 && sON==1){
sON = 0;
}

//Noise Pulse normally keeps high for about 100[usec]
if(noise==1 && nON==0)
{//Deactivate Noise Pulse counting for a while
Expand Down Expand Up @@ -203,7 +205,7 @@ double RadiationWatch::uSvhError()
}
}

RadiationWatchPrinter::RadiationWatchPrinter(int signPin, int noisePin) : RadiationWatch(signPin, noisePin)
RadiationWatchPrinter::RadiationWatchPrinter(int signPin, int noisePin, int signIRQ) : RadiationWatch(signPin, noisePin, signIRQ)
{
}

Expand Down
8 changes: 4 additions & 4 deletions RadiationWatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class RadiationWatch
{
public:
RadiationWatch(int signPin, int noisePin);
RadiationWatch(int signPin, int noisePin, int signIRQ);

void setup();
void loop();
Expand All @@ -31,18 +31,18 @@ class RadiationWatch

double cpmTime();

static const unsigned int kHistoryCount = 200;
static const unsigned int kHistoryCount = 50; // was 200

double _cpmHistory[kHistoryCount]; //History of count rates

int _prevTime;

int _signPin; //Radiation Pulse (Yellow)
int _noisePin; //Vibration Noise Pulse (White)
int _signIRQ; //The IRQ number for the radiation pulse pin (depends on Arduino model)

int index; //Number of loops

int signCount; //Counter for Radiation Pulse
int noiseCount; //Counter for Noise Pulse

int sON;//Lock flag for Radiation Pulse
Expand All @@ -63,7 +63,7 @@ class RadiationWatch
class RadiationWatchPrinter : public RadiationWatch
{
public:
RadiationWatchPrinter(int signPin, int noisePin);
RadiationWatchPrinter(int signPin, int noisePin, int signIRQ);

virtual void printKey();
virtual void printStatus();
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

An Arduino library to interface with the [Radiation Watch](http://www.radiation-watch.org/) Pocket Geiger

Based on the [Radiation Watch sample code](http://radiation-watch.sakuraweb.com/share/ARDUINO.zip).
Based on [thomasaw's library](https://github.com/thomasaw/RadiationWatch) and the [Radiation Watch sample code](http://radiation-watch.sakuraweb.com/share/ARDUINO.zip)

Changes in this version:

x) Changed from using loops for the radiation detection to interrupts

x) Added support for classic radiation "click" via speaker