#include <IRremote.h>
int timing = 5;
int mode = 0;
int rp = 6;
int rv = 0;
int gp = 10;
int gv = 0;
int bp = 9;
int bv = 0;
int RECV_PIN = 11;
int resetpin = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
irrecv.enableIRIn();
}
void loop() {
if (mode == 1) {
fading();
}
if (mode == 0){
if (irrecv.decode(&results)){
if (results.value == 1) {
if (rv == 0) {
rv = 255;
}
else {
rv = 0;
}
}
if (results.value == 2) {
if (gv == 0) {
gv = 255;
}
else {
gv = 0;
}
}
if (results.value == 3) {
if (bv == 0) {
bv = 255;
}
else {
bv = 0;
}
}
if (results.value == 9767) {
mode = 1;
rv = 0;
bv = 0;
gv = 0;
}
irrecv.resume();
analogWrite(rp, rv);
analogWrite(bp, bv);
analogWrite(gp, gv);
}
}
}
void fading() {
if (mode == 1) {
if (rv == 0 && bv == 0 && gv ==0){
for (rv == 0; rv <= 254; rv++){
analogWrite(rp, rv);
delay(timing);
}
}
}
if (mode == 1) {
if (rv == 255 && bv == 0 && gv ==0){
for (bv == 0; bv <= 254; bv++){
analogWrite(bp, bv);
delay(timing);
}
}
}
if (mode == 1) {
if (rv == 255 && bv == 255 && gv ==0){
for (rv == 255; rv >= 1; rv--){
analogWrite(rp, rv);
delay(timing);
}
}
}
if (mode == 1) {
if (rv == 0 && bv == 255 && gv ==0){
for (gv == 0; gv <= 254; gv++){
analogWrite(gp, gv);
delay(timing);
}
}
}
if (mode == 1) {
if (rv == 0 && bv == 255 && gv ==255){
for (bv == 255; bv >= 1; bv--){
analogWrite(bp, bv);
delay(timing);
}
}
}
if (mode == 1) {
if (rv == 0 && bv == 0 && gv ==255){
for (rv == 0; rv <=254; rv++){
analogWrite(rp, rv);
delay(timing);
}
}
}
if (mode == 1) {
if (rv == 255 && bv == 0 && gv ==255){
for (bv == 0; bv <=254; bv++){
analogWrite(bp, bv);
delay(timing);
}
}
}
if (mode == 1) {
if (rv == 255 && bv == 255 && gv ==255){
for (bv == 255; bv >= 1; bv--){
rv--;
gv--;
analogWrite(rp, rv);
analogWrite(bp, bv);
analogWrite(gp, gv);
delay(timing);
}
}
}
}
void ircheck() {
if (irrecv.decode(&results)) {
if (results.value == 9767) {
mode = 0;
irrecv.resume();
pinMode(8, OUTPUT);
}
}
}