Hello all!
I am making a Ionizing Radiation Detector project. It utilizes a I2C 16x2 LCD with RGB backlight to display the info. I have made a list of radiation values and their equivalent devices that emit it.
int values[] = { 1, 5, 10, 40, 100, 250, 400, 1000, 10000 };
const char* equivalent[] = { "Airport", "Dental", "Norm(1day)", "Flight", "X-Ray", "NPP(1year)", "Mammogram", "Gov Limit", "CT Scan" };
I have used this function to find the equivalent:
int nearestEqual(int x, bool sorted = true) {
int idx = 0; // by default near first element
int distance = abs(bearings[idx] - x);
for (int i = 1; i < arrSize(bearings); i++) {
int d = abs(bearings[i] - x);
if (d < distance) {
idx = i;
distance = d;
}
else if (sorted) return idx;
}
return idx;
}
I am trying to add RGB values for each equivalent[]
. Basically, a color that the display turns when one of those equivalents[]
is reached. I hope this makes sense?
I was thinking maybe something like this, but I could be totally butchering it:
const char* equalcolor[r,g,b] = {[255,0,0],[255,127,20],[255,255,0],etc.
Thanks in advance!