Okay. It's been a while. I did not figure out how to set the brightness yet. But I figured out how this rgb bitshifting works.

If anyone wants to know this I try to explain it:

First we make the variables r,g,b and set it as "byte". Since byte is only a range from 0 to 255 it's representing our brightness needed for one color (0 = low/no light | 255 = High/light on).

Now we're coming to this:

```
switch(results.value){
case RED: RGB(0x00FF0000); break;
case GREEN: RGB(0x0000FF00); break;
case BLUE: RGB(0x000000FF); break;
```

Let us just keep the case RED in mind. We hand over the value "0x00FF0000" to the RGB()-Function.

Let's look have a look on the RGB()-Function:

```
void RGB(unsigned long var) {
r = var >> 16;
g = (var >> 8) & 0xFF;
b = var & 0xFF;
}
```

Now we need an understanding for bitshifting.For getting to know bitshifting use this link: https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitshiftright/
In this case we need the right bitshifting.

Right-Bitshifting simply put:

```
bitshift_result = shifting_variable >> with bits of x
-> bitshift_rsult = shifting_variable >> 2 //We shift the binary value of "shifting_variable" 2 bits to the right.
```

Example:

```
bitshift = 5;
shift_result = bitshift >> 2 //Binary Value of 5 = 00000101
//shift_result = 00000001 = 1
```

Okay now that we know how bitshifting to the right works we can understand this:

```
r = val >> 16
```

The value of the variable "val" is shifted 16 bits to the right.
We handed the hexadecimal number 0x00FF0000 (=red) over to the RGB()-Function. That means that the variable "val" is now treated as "0x00FF0000".

Since 0x00FF0000 is a hex number, we need to translate it into binary. This would be the outcome:
0000 = First 0 (=4 Bits)
x
0000 = Second 0 (=4 Bits)
0000 = Third 0 (=4 Bits)
1111 = First F (=4 Bits)
1111 = Second F (=4 Bits)
0000 = Fourth 0 (=4 Bits)
0000 = Fifth 0 (=4 Bits)
0000 = Sixth 0 (=4 Bits)
0000 = Seventh 0 (=4 Bits)

Now we want to shift the "FF" 16 bits to the right. Coutning from above it would be like this:
0000 = 0
x = x
0000 = 0
0000 = 0
0000 = 0
0000 = 0
0000 = 0
0000 = 0
1111 = F
1111 = F

So the variable "r" has the value "0x000000FF" stored.
Now we can ignore the zeros standing in front of the "FF" and we only have the value "0xFF" left which is for decimal = 255. So now we stored the number 255 in variable "r".

**This part was for variable "r". No we need to set "g" and "b".**

Let's set the number for "g".
For "g = (var >> 8 )" we do the same as above ( I won't write it down now since you should be able to understand it) The result of this "var" would be: 0x0000FF00

Now we get another unknown thing and it is written down as "& 0xFF".
That means we make an "AND-Operation" with the result of the shifted variable "var" and the value 0xFF.
Simply put: we compare eachother if they match. For hexadecimal it would be like:

FF00

## & 00FF

= 0000

Or i binary form:

1111 1111 0000 0000

## & 0000 0000 1111 1111

= 0000 0000 0000 0000

The Table for the AND-Operation is:
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1

Only if we have a 1 and another 1 matching to eachother the result would be 1. Everything else would be 0.

So now that we compard "var" and 0xFF which ended in a result of 0 the variable "g" contains the value 0.

Finally we come to the variable "b" which is only compared with "var & 0xFF"
Now that you now how to do this I won't write it down. The Result would be: "b = 0" (remember that "var" still contains the value "0x00FF0000")

Now we're done.
We have for:
r = 255
g = 0
b = 0

Now we're handing those values to "analogWrite()" and we're done:

```
//analogWrite(PIN, Value)
analogWrite(redPin, r) //Containing value of 255
analogWrite(greenPin, g) //Containing value of 0
analogWrite(bluePin, b) //Containing value of 0
```

**Result: The Red LED is lighten up**

Now you can do that for all other colors too.

I hope you understand it.