Bonjour,
Je voudrais savoir comment m'y prendre pour déclarer un tableau constant de structures constantes.
J'explique plus présicement :
Je voudrais faire afficher de la lumière, décomposéeen trois couleurs de base (rouge, vert, bleu). Pour cela, j'ai créé une structure couleur que voici, dans un fichier color.h :
Puis la définition de plusieurs couleurs de base, dans le fichier color.c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include "types.h" struct color{ uint8_t red; uint8_t green; uint8_t blue; }; extern struct color black ; extern struct color white ; extern struct color red ; extern struct color green ; extern struct color blue ; extern struct color cyan ; extern struct color magenta ; extern struct color yellow ; extern struct color azure ; extern struct color beige ; extern struct color blueviolet; extern struct color brown ; extern struct color darkviolet; extern struct color gold ; extern struct color grey ; extern struct color ivory ; extern struct color orange ; extern struct color pink ; extern struct color turquoise; extern struct color violet;
Finalement, je crée, dans mon fichier main.c, un tableau, que je veux constant comme ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "colors.h" struct color white = {255,255,255}; struct color red = {255, 0, 0}; struct color green = {0,255,0}; struct color blue = {0,0,255}; struct color cyan = {0,255,255}; struct color magenta = {255,0,255}; struct color yellow = {255,255,0}; struct color azure = {240,255,255}; struct color beige = {245,245,220}; struct color blueviolet = {138,43,226}; struct color brown = {165,42,42}; struct color darkviolet = {148,0,211}; struct color gold = {255,215,0}; struct color grey = {128,128,128}; struct color ivory = {255,255,240}; struct color orange = {255,165,0}; struct color pink = {255,192,203}; struct color turquoise = {64,224,208}; struct color violet = {238,130,238};
Sauf que mon compilateur se plaint, que les membres white, black, ... ne sont pas des constantes...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 int main(void) { // ms_pause(100); //time for alimentation's stabilisation init(); actual_color = blue; const struct color tab_color[]={white, black, green, blue, red, yellow, cyan, magenta, azure}; pwm_init(); pwm_on(true); // while(1){ for (int j=0; j<8;++j) { pwm_set(tab_color[j]); ...
Merci de votre aide
Partager