Lab7 Embedded
Lab7 Embedded
Idea:-
We have 16-bit:-
Bits 0:4 Blue Bits 5:10 Green Bits 11:15 Red
The decimal value range for each will be:
Blue 0:31 → 0001 1111 Green 0:63 → 0011 1111 Red 0:31 → 0001 1111
But the value range read from analogRead = 0:1023 → 0011 1111 1111
So, we need mapping between 1023 → 31 for Blue&Red. → Shift the analogRead value 5-bit for
Right.
1023 → 63 for Green → Shift the analogRead value 4-bit for Right.
For Blue:When shift the value [.e.g 0011 1111 1111] 5-bit for right will be [0001 1111] , so it
doesn’t need any other shifts because Blue bits 0:4.
For Green:When shift the value [.e.g 0011 1111 1111] 4-bit for right will be [0011 1111] , but
Green bits 5:10 ,So it need another shift to be at right position [0111 1110 0000] so, shift it 5-bit
for left.
For Red:Same as Blue , but it need another shift because its bits 11:15 So shift it 11-bit for left.