hola!
ho un problema che non riesco a capire..
ho preso una stip led e lo collegata ad arduino, usando anche il telecomando ad infrarossi.
Sono arrivato a far funzionare i bottoni ed accendere i vari colori.
Ora voglio diminuire ed alzare l'intensità di luce, ma credo che mi manchi un riferimento perchè appena premo il bottone non si abbassa di 10 come dovrebbe ma m esce una luce diversa (dal bianco diventa giallo), e mi si blocca tutto.
ho provato a mettere un delay ma niente.
qui il codice fino ad esso:
#include <IRremote.h>
#define led1 9
#define led2 10
#define led3 11
int RECV_PIN = 3;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
int val = 0; // variable to store the read value
decode_results results;
byte r = 0;
byte g = 0;
byte b = 0;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
analogWrite(led1,r);
analogWrite(led2,g);
analogWrite(led3,b);
if (irrecv.decode(&results)) {
// storeCode(&results);
//Serial.println(results->value,HEX);
if (results.value == 0xF740BF) {
r=0;
g=0;
b=0;
Serial.println("spento");
}
if (results.value == 0xF7C03F) {
r=255;
g=255;
b=255;
Serial.println("acceso");
}
if (results.value == 0xF720DF) {
r=0;
g=255;
b=0;
Serial.println("rosso");
}
if (results.value == 0xF7A05F) {
r=255;
g=0;
b=0;
Serial.println("verde");
}
if (results.value == 0xF7609F) {
r=0;
g=0;
b=255;
Serial.println("blu");
}
if (results.value == 0xF7E01F) {
r=255;
g=255;
b=255;
Serial.println("bianco");
}
if((results.value==0xF700FF) && (r<245) && (g<245) && (b<245)) { //245+10=255
r = r+10;
g = g+10;
b = b+10;
Serial.println("aumento");
}
if (results.value==0xF7807F) {
r = r-10;
g = g-10;
b = b-10;
Serial.println("diminuisco");
}
irrecv.resume(); // resume receiver
}
delay(10);
}