]> git.piffa.net Git - sketchbook_andrea/blob - programming/pointers_c/structure_pointers_function_stack_4/structure_pointers_function_stack_4.ino
operatori + analog
[sketchbook_andrea] / programming / pointers_c / structure_pointers_function_stack_4 / structure_pointers_function_stack_4.ino
1
2
3 struct RGB {
4   byte r;
5   byte g;
6   byte b;
7
8 myLED ;
9
10 void setup() {    
11   Serial.begin(9600);
12   // Serial link to PC
13 }
14 void loop() {
15   myLED = {
16     100,200,255 }  
17   ;
18
19   // Serial.println(myLED.r) ;
20
21   illumina(&myLED);
22   rossa(&myLED);
23   Serial.println();
24   illumina(&myLED);
25
26   Serial.flush();
27   exit(0);
28 }
29
30 void  illumina(struct RGB *tempLED) { // Function with a pointer
31   Serial.println((*tempLED).r) ; // This does not waste STACK space
32   Serial.println((*tempLED).g) ; // Note: indirect operator * has lower priority
33   Serial.println(tempLED->b) ; // than dot . operator , so the parentheses
34                     // That is the dereference -> operator
35 }
36
37 struct RGB rossa(struct RGB *temp) { // Function with a pointer:
38         // This can change directly the original value without the need
39         // to reassign as in: myLED = rossa(myLED)
40   (*temp).r = 255 ;  
41   //return *temp;
42 }
43
44
45
46
47