c - Fill an array with an array? -
i'm doing electronics: i've got 12 rgb leds in circle (i call heel wheel). i'll "pulsing" each led colour in line pre-defined "levels": see below, level02 example means colour led pulsed twice every 10 cycles... code cycle through 12 leds 1 @ time. 1 cycle = 12 leds... 10 cycles = 1 colour level loop
essentially want pixel[1] = colour1
, or pixel[5] = colour9
etc... pixel
array heelwheel
below, , colour
set of constant char
arrays clred
, clrrg
etc... ok, more detail:
// color level definitions #define level00 "0000000000" #define level01 "1000000000" #define level02 "1000010000"
etc... level10
char heelwheel[12][3]; //wheel pixel: led, colour (red, green, blue) // colour definitions: defining mix of colour levels 12 standard colours //(12 coincidentally == number of leds: no particular reason) const char *clred[3] = {level10, level00, level00} ; // full red const char *clrrb[3] = {level06, level00, level04} ; // red, bit of blue const char *clrab[3] = {level05, level00, level05} ; // purple
etc... 12 colours
so want able set each of 12 "pixels" specifying 1 of 12 colours... e.g.
heelwheel[0] = clred ; heelwheel[1] = clrrb ;
i hope it's clear i'm trying do... theory i've defined heelwheel
2 dimensional array: instead of individually setting 3 values in second dimension, want these 3 values = 3 values contained in three-value colour arrays
gcc error = "incompatible types when assigning type char *[3] type const char **"...
i've tried understand numerous resources on arrays in c , stuff "sticking" i'm beginner @ c, i'm reaching headache territory quite quickly.
don't use string-like data types this, since strings represented arrays in c , arrays not assignable.
encode color in integer, typical choice uint32_t
full 24-bit rgb, 8 bits spare.
then you'd have:
uint32_t heelwheel[12];
and colours defined so:
/* these assume red in msbs, blue in lsbs. */ const uint32_t red = 0xff0000; const uint32_t purple = 0xff00ff; const uint32_t yellow = 0xffff00; /* , on */
and can assign directly, no problems:
heelwheel[0] = red; heelwheel[1] = purple;
Comments
Post a Comment