1
14
15#include <Adafruit_GFX.h>
16#include <Adafruit_SSD1331.h>
17#include <SPI.h>
18
19#define sclk 13
20#define mosi 11
21#define cs 10
22#define rst 9
23#define dc 8
24
25#define LOGtime 1000
26#define Minute 60000
27
28#define show endWrite
29#define clear() fillScreen(0)
30
31
32#define BLACK 0x0000
33#define BLUE 0x001F
34#define RED 0xF800
35#define GREEN 0x07E0
36#define CYAN 0x07FF
37#define MAGENTA 0xF81F
38#define YELLOW 0xFFE0
39#define WHITE 0xFFFF
40
41Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);
42
43int Counts = 0;
44unsigned long previousMillis = 0;
45int AVGCPM = 0;
46int TenSecCPM = 0;
47int units = 0;
48int tens = 0;
49int hundreds = 0;
50int thousands = 0;
51float Sievert = 0;
52
53int COUNTS[10];
54int t = 0;
55
56
57void setup() {
58
59 Serial.begin(115200);
60 display.begin();
61 display.fillScreen(BLACK);
62
63 float Battery = analogRead(A3);
64 float BattPerc = 100 * (Battery/770);
65
66
67 display.setCursor(4,4);
68 display.setTextSize(2);
69 display.setTextColor(MAGENTA);
70 display.println("Battery");
71 display.setCursor(4,24);
72 display.print (int (BattPerc)); display.print("."); display.print (int((10*BattPerc)-(10*int(BattPerc)))); display.print(" %");
73 delay(3000);
74 display.fillScreen(BLACK);
75
76 for (int x = 0; x < 10 ; x++) {
77 COUNTS[x] = 0;
78 }
79
80 attachInterrupt(0, IMPULSE, FALLING);
81
82 display.drawRect(0,0,96,64,WHITE);
83 display.setCursor(4,4);
84 display.setTextColor(RED);
85 display.setTextSize(2);
86 display.print("CPM");
87 display.setCursor(50,4);
88 display.setTextSize(1);
89 display.print("10 sec");
90 display.setCursor(50,12);
91 display.print("window");
92
93 display.setCursor(4,38);
94 display.setTextSize(1);
95 display.setTextColor(GREEN);
96 display.print("uSv/hr");
97
98 display.drawRect(0,48, 96, 16, YELLOW);
99}
100
101
102void loop()
103{
104 unsigned long currentMillis = millis();
105 if(currentMillis - previousMillis > LOGtime)
106 {
107 previousMillis = currentMillis;
108
109 COUNTS[t] = Counts;
110 for (int y = 0; y < 10 ; y++) {
111 TenSecCPM = TenSecCPM + COUNTS[y];
112 }
113 AVGCPM = 6* TenSecCPM;
114 TenSecCPM = 0;
115 t++ ;
116 if (t > 9) { t = 0 ;}
117
118
119 display.fillRect(4,20,90,17,BLACK);
120 display.setCursor(4,20);
121 display.setTextColor(RED);
122 display.setTextSize(2);
123 display.println(AVGCPM);
124
125
126 display.fillRect(45,38,50,10,BLACK);
127 display.setCursor(45,38);
128 display.setTextColor(GREEN);
129 display.setTextSize(1);
130
131 Sievert = (AVGCPM /151.0) ;
132 units = int (Sievert);
133 tens = int ((10*Sievert) - (10*units));
134 hundreds = int ((100*Sievert) - (100*units) - (10* tens));
135 thousands = int ((1000*Sievert) - (1000*units) - (100*tens) - (10*hundreds));
136 display.print (units); display.print("."); display.print (tens); display.print (hundreds); display.println (thousands);
137
138 display.fillRect(1,49,94,14,BLACK);
139 display.fillRect(1,49,Counts,14,RED);
140
141 Counts = 0;
142 }
143}
144
145
146
147void IMPULSE()
148 {
149 Counts++;
150 }