Hello to everyone,
This is my first post so please excuse me if I'm in the wrong section.
I want to make an IR receiver using a vs1838b ir receiver and the attiny85 to switch an led with a fading effect.
The problem that i face is that althought I managed the code to work correct on the arduino board, loading it to the attiny works too but not doing the fading routine.
I use the tinycore from David A. Mellis and the IRremote library ported from N. Gammon for the attiny.
Everything compiles ok and works except the fade routine .
I am a newbie on arduinos so everything in the code are bits and pieces from examples and other projects that i have connected.
Here is the code that is being used:
#include <IRremote.h>
#include <IRremoteInt.h>/*
source: www.electroschematics.com
You'll need to change the led pins and the codes
accordingly to your configuration and IR remote
*/int RECV_PIN = 4; // the pin where you connect the output pin of TSOP4838
int led1 = 1;
//int led2 = 4;
//int led3 = 7;
int itsONled[] = {
0, 0, 0, 0 };/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1's if you want a certain
led to light when the board is powered */#define code1 0xFFA25D // code received from button on/off
#define code2 0xFFA857 // code received from button -
#define code3 0xFF906F // code received from button +IRrecv irrecv(RECV_PIN);
decode_results results;void setup()
{
irrecv.enableIRIn(); // Start the receiver
pinMode(led1, OUTPUT);
// pinMode(led2, OUTPUT);
// pinMode(led3, OUTPUT);
// digitalWrite(3, LOW);
}void loop()
{
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch (value) {
case code1:
if (itsONled[1] == 1) { // if first led is on then
fadeOff();
itsONled[1] = 0; // and set its state as off
}
else { // else if first led is off
fadeOn();
itsONled[1] = 1; // and set its state as on
break;}
}
/*
case code2:
if (itsONled[1] == 1) {
brightness = brightness - fadeAmount;
analogWrite(led1, brightness);
itsONled[1] = 0;} else {
digitalWrite(led1, HIGH);
itsONled[2] = 1;
}
break;
/* case code3:
if (itsONled[3] == 1) {
digitalWrite(led3, LOW);
itsONled[3] = 0;
} else {
digitalWrite(led3, HIGH);
itsONled[3] = 1;
}
break;
}
*/
irrecv.resume(); // Receive the next value
}
}void fadeOff()
{
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(led1, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}void fadeOn()
{
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(led1, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
Any help will be much appreciated.