forked from WinHGGG/Geiger-Counter-v1.3-LCD-CAJOE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeiger_Counter_Code.ino
153 lines (68 loc) · 2.15 KB
/
Geiger_Counter_Code.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //从库管理器添加1602I2C库
#include <SPI.h>
#define LOG_PERIOD 15000
#define MAX_PERIOD 60000
unsigned long counts; // GM 变量
unsigned long cpm; // CPM 变量
unsigned int multiplier; //设置换算变量
unsigned long previousMillis; //测量时间
float usv;
LiquidCrystal_I2C lcd(0x27, 16, 2); //设置LCD地址为 0x27 (1602显示器)
void tube_impulse() { //自加
counts++;
}
void setup()
{
counts = 0;
cpm = 0; //计数
multiplier = MAX_PERIOD / LOG_PERIOD; //计算乘数,取决于周期
//Serial.begin(9600);
attachInterrupt(0, tube_impulse, FALLING); //中断为下降沿触发
//////////////////
lcd.init();
// 输出数据到屏幕
lcd.backlight();
lcd.setCursor(5, 0);
lcd.print("Boot..."); //写一个开机boot加载的画面,提供一个盖革管启动的时间。
lcd.setCursor(0, 1);
for(int i=0;i<16;i++)
{
lcd.write(0xff);
delay(250);
}
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > LOG_PERIOD) {
previousMillis = currentMillis;
cpm = counts * multiplier;//得出技术次数
usv = float(cpm) / 151;//带入公式计算出辐射强度
lcd.clear();
lcd.print("CPM=");
lcd.print(cpm);//输出cpm值
lcd.setCursor(0, 1);//第二行
lcd.print(usv);
lcd.print(" uSv/h");//输出强度值
counts = 0;//复位
if (usv >= 10)
{
lcd.setCursor(9, 0);
lcd.print("Danger!");//如果辐射大于10则显示危险
delay(0.1);
}
else if (usv < 10 && usv >= 0.52)
{
lcd.setCursor(10, 0);
lcd.print("Unsafe");//在0.52-10这个范围显示不安全
delay(0.1);
}
else if (usv < 0.52)
{
lcd.setCursor(10, 0);
lcd.print("Safety");//在这个值以下显示安全
delay(0.1);
}
}
}