Galera estou fazendo um programa aqui que recebe dados a partir de um controle remoto (utilizando um receptor infravermelho) para ajustar o brilho de um led. Porém, aparentemente a função analogWrite não está funcionando corretamente. Testei outros programas que utilizavam PWM e funcionam perfeitamente, mas o meu não! Por favor, deem uma olhada no meu código e vejam se estou aplicando a função de forma errada:
#include <IRremote.h>
#define Botplay 16761405
#define Botmais 16754775
#define Botmenos 16769055
#define Bot1 16724175
#define Bot2 16718055
#define Bot3 16743045
#define Bot4 16716015
#define Bot5 16726215
#define Bot6 16734885
#define Bot7 16728765
#define Bot8 16730805
#define Bot9 16732845
#define Bot0 16738455
int RECV_PIN = 2;
int pinoLed = 3;
int cont1 = 0;
int cont2 = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
Serial.flush();
pinMode(pinoLed, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
if(results.value != Botplay){
cont1 = cont1*10;
}
if(results.value == Botplay){
Serial.print("cont1 ");
Serial.println(cont1);
cont1 = constrain(cont1,0,255);
Serial.print("cont1 ");
Serial.println(cont1);
analogWrite(pinoLed, cont1);
cont1 = 0;
cont2 = 0;
}
Serial.print("Botao: ");
if (results.value == Bot1){
Serial.println(1);
cont1 = cont1 + 1;
cont2 = cont2 + 1;
}
if (results.value == Bot2){
Serial.println(2);
cont1 = cont1 + 2;
cont2 = cont2 + 1;
}
if (results.value == Bot3){
Serial.println(3);
cont1 = cont1 + 3;
cont2 = cont2 + 1;
}
if (results.value == Bot4){
Serial.println(4);
cont1 = cont1 + 4;
cont2 = cont2 + 1;
}
if (results.value == Bot5){
Serial.println(5);
cont1 = cont1 + 5;
cont2 = cont2 + 1;
}
if (results.value == Bot6){
Serial.println(6);
cont1 = cont1 + 6;
cont2 = cont2 + 1;
}
if (results.value == Bot7){
Serial.println(7);
cont1 = cont1 + 7;
cont2 = cont2 + 1;
}
if (results.value == Bot8){
Serial.println(8);
cont1 = cont1 + 8;
cont2 = cont2 + 1;
}
if (results.value == Bot9){
Serial.println(9);
cont1 = cont1 + 9;
cont2 = cont2 + 1;
}
if (results.value == Bot0){
Serial.println(0);
cont1 = cont1 + 0;
cont2 = cont2 + 1;
}
Serial.print("contador1 : ");
Serial.println(cont1);
Serial.print("contador2 : ");
Serial.println(cont2);
if (cont2>=3){
cont1 = constrain(cont1,0,255);
analogWrite(pinoLed, cont1);
cont1 = 0;
cont2 = 0;
}
//Serial.println(results.value);