Skip to content

Commit afb6995

Browse files
add optional support for WS2812 RGB LED, fixes #106
specific indexes in the LED color time sequence are used for: - dark separator indicates "start of sequence" (also used for LED init and re-init) - color according to indications (3bits encoded via RGB color) (can be extended to show up to 32 indication bits) (dark if there is nothing to indicate) - white separator indicates "start of radiation display" (also works as LED test, white = R on + G on + B on) - color according to radiation (repeated, displayed most of the time) dark (unusually low / 0) green (normal) yellow (more than normal) red (much more than normal)
1 parent 0599416 commit afb6995

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

multigeiger/multigeiger.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
#include <Adafruit_Sensor.h>
8585
#include <Adafruit_BME280.h>
8686

87+
// for RGB LED
88+
#include "status_led.h"
8789

8890
// Check if a CPU (board) with LoRa is selected. If not, deactivate SEND2LORA.
8991
#if !((CPU==LORA) || (CPU==STICK))
@@ -532,6 +534,9 @@ void loop()
532534

533535
Dose_Rate = Count_Rate *GMC_factor_uSvph; // ... and dose rate
534536

537+
// indicate status on RGB LED (if any)
538+
indicate(Dose_Rate, I_TEST);
539+
535540
// calculate the radiation over the complete time from start
536541
accumulated_Count_Rate = 0.0;
537542
if (accumulated_time != 0) {

multigeiger/status_led.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// show status indication via WS2812 RGB LED
2+
3+
#include "userdefines.h"
4+
5+
#if STATUS_LED==1 // we have a WS2812 RGB LED!
6+
7+
#include <NeoPixelBus.h>
8+
9+
#include "status_led.h"
10+
11+
#define PIXEL_COUNT 1
12+
#define PIXEL_PIN 25
13+
14+
RgbColor red(255, 0, 0);
15+
RgbColor green(0, 255, 0);
16+
RgbColor blue(0, 0, 255);
17+
RgbColor yellow(255, 255, 0);
18+
RgbColor white(255, 255, 255);
19+
RgbColor black(0, 0, 0);
20+
21+
NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod> LEDs(PIXEL_COUNT, PIXEL_PIN);
22+
23+
static RgbColor last_col = black;
24+
25+
void set_LED(RgbColor col)
26+
{
27+
if(col == last_col)
28+
return; // nothing to change
29+
30+
LEDs.SetPixelColor(0, col); // only 1 LED at index 0
31+
LEDs.Show();
32+
last_col = col;
33+
}
34+
35+
void init_LED(void) {
36+
LEDs.Begin(); // all LEDs off
37+
LEDs.Show();
38+
last_col = black; // consistency sw state == hw state
39+
}
40+
41+
#define IDX_W 2
42+
#define CSL 30
43+
44+
void indicate(float radiation, unsigned int indication)
45+
{
46+
// radiation [uSv/h] given to set the primary color R that is shown most of the time
47+
// indication: 32 bit flags to indicate additional stuff, see status_led.h.
48+
//
49+
// this code will generate a time sequence of LED colors:
50+
// index color
51+
// ------------------------------------------------------
52+
// 0 dark (LED init)
53+
// 1 indication color 1
54+
// ... reserved for more indications
55+
// IDX_W white (LED test)
56+
// ...+1 radiation color
57+
// ... radiation color
58+
// CSL-1 radiation color
59+
60+
RgbColor col;
61+
int r, g, b;
62+
static int index = 0; // index counting modulo COLOR_SEQUENCE_LENGTH
63+
64+
switch(index) {
65+
case 0: // show a fixed dark separator after LED init
66+
init_LED(); // (re-)init the LED
67+
col = black;
68+
break;
69+
case 1:
70+
r = indication & I_CONN_ERROR;
71+
g = indication & I_TEST;
72+
b = indication & I_HV_ERROR;
73+
col = RgbColor(r ? 255 : 0, g ? 255 : 0, b ? 255 : 0);
74+
break;
75+
case IDX_W: // show a fixed white separator and LED test
76+
col = white;
77+
break;
78+
default: // show radiation color
79+
if(radiation > 1.0) {
80+
col = red;
81+
} else
82+
if(radiation > 0.2) {
83+
col = yellow;
84+
} else
85+
if(radiation > 0.01) {
86+
col = green;
87+
} else {
88+
col = black;
89+
}
90+
}
91+
92+
set_LED(col);
93+
94+
if(++index == CSL)
95+
index = 0;
96+
}
97+
98+
#else // no STATUS_LED
99+
100+
void indicate(float radiation, unsigned int indication) {
101+
// do nothing
102+
}
103+
104+
#endif // STATUS_LED
105+

multigeiger/status_led.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// show status indication via WS2812 RGB LED
2+
3+
// indication value used to reset indications to "all off"
4+
#define I_RESET 0
5+
6+
// indications, values are 32bit bit masks, valid values are 2^N
7+
#define I_TEST 1 // reserved to test the indication code
8+
#define I_HV_ERROR 2 // there is a problem with high voltage generation
9+
#define I_CONN_ERROR 4 // there is a problem with the network connection
10+
11+
// indicate radiation and special indications via a color time sequence.
12+
// you should call this in regular time intervals [e.g. 1s].
13+
void indicate(float radiation, unsigned int indication);

multigeiger/userdefines-example.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
// Note: The TTN configuration needs to be done in lorawan.cpp (starting at line 65).
5858
#define SEND2LORA 0
5959

60+
// 0: no RGB status LED, 1: WS2812B status LED
61+
#define STATUS_LED 1
62+
6063
// *********************************************************************************
6164
// END of user changeable parameters. Do not edit beyond this point!
6265
// *********************************************************************************

0 commit comments

Comments
 (0)