ciao a tutti! come faccio a far variare di colore i miei 3 led rgb? non intendo cambiare colore subito, ma passare da un colore ad un altro passando attraverso altre tonalità!
questo è lo sketch
#include <IRremote.h>
int RECV_PIN = A3;
int red1 = 13; //pin per il led rosso
int green1 = 12; //pin per il led verde
int blue1 = 11; //pin per il led blu
int red2 = 10;
int green2 = 9;
int blue2 = 8;
int red3 = 7;
int green3 = 6;
int blue3 = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // ricezione
//impostazione pin come uscita
pinMode(red1, OUTPUT);
pinMode(green1, OUTPUT);
pinMode(blue1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(green2, OUTPUT);
pinMode(blue2, OUTPUT);
pinMode(red3, OUTPUT);
pinMode(green3, OUTPUT);
pinMode(blue3, OUTPUT);
pinMode (RECV_PIN, INPUT);
digitalWrite(red1,LOW);
digitalWrite(green1,LOW);
digitalWrite(blue1,LOW);
// secondo led
digitalWrite(red2,LOW);
digitalWrite(green2,LOW);
digitalWrite(blue2,LOW);
// terzo led
digitalWrite(red3,LOW);
digitalWrite(green3,LOW);
digitalWrite(blue3,LOW);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
if (irrecv.decode(&results)) {
if (results.value == 0xB5210DA6) { // giallo
analogWrite(red1,255);
analogWrite(green1,180);
analogWrite(blue1,0);
// secondo led
analogWrite(red2,255);
analogWrite(green2,180);
analogWrite(blue2,0);
// terzo led
analogWrite(red3,255);
analogWrite(green3,180);
analogWrite(blue3,0);
}
if (results.value == 0xE13DDA28) { // bianco
analogWrite(red1,255);
analogWrite(green1,255);
analogWrite(blue1,255);
// secondo led
analogWrite(red2,200);
analogWrite(green2,200);
analogWrite(blue2,200);
// terzo led
analogWrite(red3,200);
analogWrite(green3,200);
analogWrite(blue3,200);
}
if (results.value == 0xDAEA83EC) { // rosso
analogWrite(red1,255);
analogWrite(green1,0);
analogWrite(blue1,0);
// secondo led
analogWrite(red2,200);
analogWrite(green2,0);
analogWrite(blue2,0);
// terzo led
analogWrite(red3,200);
analogWrite(green3,0);
analogWrite(blue3,0);
}
if (results.value == 0x2BAFCEEC) { // verde
analogWrite(red1,0);
analogWrite(green1,255);
analogWrite(blue1,0);
// secondo led
analogWrite(red2,0);
analogWrite(green2,200);
analogWrite(blue2,0);
// terzo led
analogWrite(red3,0);
analogWrite(green3,200);
analogWrite(blue3,0);
}
if (results.value == 0x71A1FE88) { // blu
analogWrite(red1,0);
analogWrite(green1,0);
analogWrite(blue1,255);
// secondo led
analogWrite(red2,0);
analogWrite(green2,0);
analogWrite(blue2,200);
// terzo led
analogWrite(red3,0);
analogWrite(green3,0);
analogWrite(blue3,200);
}
if (results.value == 0x974F362) { // spento
digitalWrite(red1,LOW);
digitalWrite(green1,LOW);
digitalWrite(blue1,LOW);
// secondo led
digitalWrite(red2,LOW);
digitalWrite(green2,LOW);
digitalWrite(blue2,LOW);
// terzo led
digitalWrite(red3,LOW);
digitalWrite(green3,LOW);
digitalWrite(blue3,LOW);
}
}
}
grazie per le risposte