]> git.piffa.net Git - sketchbook_andrea/blobdiff - RGB_LED/rgb_5_struct/rgb_5_struct.ino
Loop e data type strutturati
[sketchbook_andrea] / RGB_LED / rgb_5_struct / rgb_5_struct.ino
index 1372da7e6f9d2966526eb815bac439ec6447f140..181a90dbb2585b02ffe3d8e734e7861a748824ab 100644 (file)
@@ -1,8 +1,8 @@
 /*
-    Adafruit Arduino - Lesson 3. RGB LED
+    RGB struct LED
 
  RGB LED: mpostare i colori per un LED RGB
- common anode
+ common anode utilizzando uno struct
 
  Schema: http://lab.piffa.net/schemi/rgb.jpg
  */
@@ -18,7 +18,6 @@ struct color {
 
 color led;
 
-
 void setup()
 {
   for (byte i = 0; i < 4; i++) {
@@ -26,7 +25,6 @@ void setup()
   }
 }
 
-
 void loop()
 {
   analogWrite(pin[0], led.red);
@@ -43,9 +41,36 @@ void loop()
  3. Sarebbe piu' elegante scrivere una funzione per gestire il setup dei PIN
  e impostare i colori?
  3.1 Servira' una o piu' funzioni?
- 4. Esiste un costrutto che mi permetta di legare le differenti caratteristiche
+ 4. Esiste un costrutto che mi permetta di legare le differenti proprieta'
  del LED RGB e contemporaneamente raggruppare le funzioni che tipicamente uso con questo?
  */
 
 
+/* Risposte:
+ *  1.
+
+struct ledRGB {
+    byte rPin ;     // PINS
+    byte gPin;
+    byte bPin;
+    byte    blue;   // Colors
+    byte    green;
+    byte    red;
+};
+
+ledRGB led {9,10,11,0,255,255};
+   
+void setup()
+{
+  pinMode(led.rPin, OUTPUT);
+  pinMode(led.gPin, OUTPUT);
+  pinMode(led.bPin, OUTPUT);
+}
 
+void loop()
+{
+  analogWrite(led.rPin,led.red );
+  analogWrite(led.gPin,led.green);
+  analogWrite(led.bPin,led.blue);
+}
+*/