X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=programming%2Fpointers_c%2Fstructure_pointers_function_stack_4%2Fstructure_pointers_function_stack_4.ino;fp=programming%2Fpointers_c%2Fstructure_pointers_function_stack_4%2Fstructure_pointers_function_stack_4.ino;h=2ebc909e109726769d30d43d5c90d39190a3ee39;hb=e50f2cf8e7402ea56cd01835be9f88c53876bfd1;hp=0000000000000000000000000000000000000000;hpb=f7cdba7df419dcde095f911daa92deb9dcd283ec;p=sketchbook_andrea diff --git a/programming/pointers_c/structure_pointers_function_stack_4/structure_pointers_function_stack_4.ino b/programming/pointers_c/structure_pointers_function_stack_4/structure_pointers_function_stack_4.ino new file mode 100644 index 0000000..2ebc909 --- /dev/null +++ b/programming/pointers_c/structure_pointers_function_stack_4/structure_pointers_function_stack_4.ino @@ -0,0 +1,47 @@ + + +struct RGB { + byte r; + byte g; + byte b; +} +myLED ; + +void setup() { + Serial.begin(9600); + // Serial link to PC +} +void loop() { + myLED = { + 100,200,255 } + ; + + // Serial.println(myLED.r) ; + + illumina(&myLED); + rossa(&myLED); + Serial.println(); + illumina(&myLED); + + Serial.flush(); + exit(0); +} + +void illumina(struct RGB *tempLED) { // Function with a pointer + Serial.println((*tempLED).r) ; // This does not waste STACK space + Serial.println((*tempLED).g) ; // Note: indirect operator * has lower priority + Serial.println(tempLED->b) ; // than dot . operator , so the parentheses + // That is the dereference -> operator +} + +struct RGB rossa(struct RGB *temp) { // Function with a pointer: + // This can change directly the original value without the need + // to reassign as in: myLED = rossa(myLED) + (*temp).r = 255 ; + //return *temp; +} + + + + +