> On Sun, Aug 17, 2014 at 4:38 AM, Ruben J=F6nsson wr= ote: > > Have you considered using a union for that: > > union { > uint32_t rgb_= 32; > =20 > struct { > uint8_t red:8; > uint8_t green:8; > unit8_t blue:8= ; > =20 > }col; > }rgb; > > This way you can access the 32 bit value with rgb.rgb_3= 2 and, > for > example red with rgb.col.red for both reading and writing. > > You = can > still use the shift/multiply methods with rgb.rgb_32 (but you > need to k= now how > the bitfields are ordered by the compiler). > > The union means that the > variables within it shares the same memory > (rgb_32 and col in this case= ). >=20 > Hi Ruben, >=20 > Actually, this was going to be my next step! I wanted to make sure I > could send enough data to get control of the LEDs first, before I > started playing with different memory structures. >=20 > Since you've raised it, one of the things that's always confused me > about unions is in the declaration process. For instance, take your > code snippet above. I understand the parts, though I'm unsure about > the "rgb" at the end. Is that defining the new datatype, that I could > then use to declare variables? For your following code, would I have > had to declare "rgb rgb;" first? >=20 > Further, since I'm using these LEDs in a string, I'm storing their > values in an array. Could I then just declare an array like this: rgb > led_colors[8]; (as an example)? >=20 > Thanks! >=20 > Josh Well actually it could be something like this instead: typedef union { uint32_t rgb_32; struct { uint8_t red:8; uint8_t green:8; uint8_t blue:8; uint8_t pad:8; }col; }RGB; Then you can do: RGB rgb; rgb.col.red=3D12; An array would also be fine: RGB rgb[10]; rgb[5].col.red=3D12; If you don't have the typedef you need to explicitly declare it as: union RGB rgb; /Ruben =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Ruben J=F6nsson AB Liros Electronic Box 9124, 200 39 Malm=F6, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .