/*
- 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
*/
color led;
-
void setup()
{
for (byte i = 0; i < 4; i++) {
}
}
-
void loop()
{
analogWrite(pin[0], led.red);
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);
+}
+*/