]> git.piffa.net Git - sketchbook_andrea/blobdiff - 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
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 (file)
index 0000000..2ebc909
--- /dev/null
@@ -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;
+}
+
+
+
+
+