hello,
i've question irremote libary. how (and it) possible check if there been new button pressed during subroutine.
i'm wondering because of fade , smooth routine in code. right if press button routine runs ones , i've press button again. want keeps running until press other button on te remote. part of keeping running can while loop, can't out of routine.
i hope can give me clue.
my code based on 1 in this link.
kind regards,
john
ps: @the mods, first post here, if it's in wrong section feel free move right section.
code:
i've question irremote libary. how (and it) possible check if there been new button pressed during subroutine.
i'm wondering because of fade , smooth routine in code. right if press button routine runs ones , i've press button again. want keeps running until press other button on te remote. part of keeping running can while loop, can't out of routine.
i hope can give me clue.
my code based on 1 in this link.
kind regards,
john
ps: @the mods, first post here, if it's in wrong section feel free move right section.
code:
code: [select]
/*
* ir rgb led remote control
* receiver type: tsop1736/38
* autor: john de graaf
* date: 12/4/2015
*/
#include <irremote.h>
#include <irremoteint.h>
int recv_pin = 4;
int r_pin = 6;
int g_pin = 9;
int b_pin = 10;
#define on 0xfff0c41643
#define off 0xffe721c0db
#define brightness_up 0xffe5cfbd7f
#define brightness_down 0xffa23c94bf
#define flash 0xff7ec31ef7
#define strobe 0xfffa3f159f
#define fade 0xffdc0197db
#define smooth 0xff9716be3f
#define red 0xff97483bfb
#define green 0xff86b0e697
#define blue 0xff9ef4941f
#define white 0xffa3c8eddb
#define orange 0xff5be75e7f
#define yellow_dark 0xffd7e84b1b
#define yellow_medium 0xff2a89195f
#define yellow_light 0xff488f3cbb
#define green_light 0xfff377c5b7
#define green_blue1 0xffee4eccfb
#define green_blue2 0xfff63c8657
#define green_blue3 0xff13549bdf
#define blue_red 0xffc101e57b
#define purple_dark 0xff51e43d1b
#define purple_light 0xff44c407db
#define pink 0xff35a9425f
unsigned long rgb = 0;
byte r, g, b;
byte r1, g1, b1;
byte onoff = 2;
byte dim = 100, time = 100;
long currentmillis;
irrecv irrecv(recv_pin);
decode_results results;
void setup()
{
irrecv.enableirin(); // initiolise ir recveiver
serial.begin(9600);
pinmode(r_pin, output);
pinmode(g_pin, output);
pinmode(b_pin, output);
pinmode(13, output);
digitalwrite(13, high);
}
void rgb(unsigned long amount) {
r = amount >> 16;
g = (amount >> 8) & 0xff;
b = amount & 0xff;
}
//-------------------------------------------------------------
void timer(int interval) {
currentmillis = millis();
while (millis() - currentmillis < interval) {
if (irrecv.decode(&results)) {
if (results.value != 0xffffffff)
return;
}
irrecv.resume(); // receive next value
}//while end
}
void flash() {
}
void strobe() {
}
void fade() {
r = 255;
g = 0;
b = 0;
for ( int = 0 ; < 255 ; i++ ) {
r--;
g++;
colortoled();
timer(time);
}
r = 0;
g = 255;
b = 0;
for ( int = 0 ; < 255 ; i++ ) {
g--;
b++;
colortoled();
timer(time);
}
r = 0;
g = 0;
b = 255;
for ( int = 0 ; < 255 ; i++ ) {
r++;
b--;
colortoled();
timer(time);
}
if (irrecv.decode(&results)) {
if (results.value != 0xffffffff)
return;
}
irrecv.resume(); // receive next value
}
void smooth() {
r = 255;
g = 0;
b = 0;
for ( int = 0 ; < 255 ; i++ ) {
g++;
colortoled();
timer(time);
}
r = 255;
g = 255;
b = 0;
for ( int = 0 ; < 255 ; i++ ) {
r--;
colortoled();
timer(time);
}
r = 0;
g = 255;
b = 0;
for ( int = 0 ; < 255 ; i++ ) {
b++;
colortoled();
timer(time);
}
r = 0;
g = 255;
b = 255;
for ( int = 0 ; < 255 ; i++ ) {
g--;
colortoled();
timer(time);
}
r = 0;
g = 0;
b = 255;
for ( int = 0 ; < 255 ; i++ ) {
r++;
colortoled();
timer(time);
}
r = 255;
g = 0;
b = 255;
for ( int = 0 ; < 255 ; i++ ) {
b--;
colortoled();
timer(time);
}
if (irrecv.decode(&results)) {
if (results.value != 0xffffffff)
return;
}
irrecv.resume(); // receive next value
}
//-------------------------------------------------------------
void colortoled() {
serial.println(results.value , hex);
serial.println(r , dec);
serial.println(g , dec);
serial.println(b , dec);
serial.println(dim);
serial.println('-');
if (r != 0 | onoff == 1) {
r1 = r;
}
if (g != 0 | onoff == 1) {
g1 = g;
}
if (b != 0 | onoff == 1) {
b1 = b;
}
analogwrite(r_pin, r * dim / 100);
analogwrite(g_pin, g * dim / 100);
analogwrite(b_pin, b * dim / 100);
}
void loop() {
if (irrecv.decode(&results)) {
if ( results.value != 0xffffffff) {
switch (results.value) {
case off :
r = g = b = 0;
onoff = 2;
break;
case on :
r = r1;
g = g1;
b = b1;
onoff = 1;
break;
}
if (onoff == 1) {
switch (results.value) {
case brightness_up :
if (dim < 100) {
dim = dim + 10;
} else {
dim = 100;
}
break;
case brightness_down :
if (dim > 0) {
dim = dim - 10;
} else {
dim = 0;
}
break;
case red : rgb(0x00ff0000); break;
case green : rgb(0x0000ff00); break;
case blue : rgb(0x000000ff); break;
case white : rgb(0x00ffffff); break;
case orange : rgb(0x00ff3000); break;
case yellow_dark : rgb(0x00ff7000); break;
case yellow_medium : rgb(0x00ffaa00); break;
case yellow_light : rgb(0x00ffd400); break;
case green_light : rgb(0x0000ff30); break;
case green_blue1 : rgb(0x0000aaaa); break;
case green_blue2 : rgb(0x0000cccc); break;
case green_blue3 : rgb(0x0000ffff); break;
case blue_red : rgb(0x00100080); break;
case purple_dark : rgb(0x005000bf); break;
case purple_light : rgb(0x007a00bf); break;
case pink : rgb(0x00ff00ff); break;
case flash : flash(); break;
case strobe : strobe(); break;
case fade : fade(); break;
case smooth : smooth(); break;
}
}
colortoled();
irrecv.resume(); // receive next value
}
}
}
hi,
the real, unwelcome, answer should not have written sketch that, or used sketch, in first place. way written not going lend want want. loops with, in effect, delay commands in them.
but before embark on re-write, try this:
replace each of these lines:
with this:
i've never used ir library, might have got wrong. idea cut short loops once ir code has been received. above cut loop short if code received during loop, , stop remaining loops in sequence running also.
paul
the real, unwelcome, answer should not have written sketch that, or used sketch, in first place. way written not going lend want want. loops with, in effect, delay commands in them.
but before embark on re-write, try this:
replace each of these lines:
code: [select]
for ( int = 0 ; < 255 ; i++ ) {
with this:
code: [select]
for ( int = 0 ; < 255 && results.value == 0xffffffff ; i++ ) {
i've never used ir library, might have got wrong. idea cut short loops once ir code has been received. above cut loop short if code received during loop, , stop remaining loops in sequence running also.
paul
Arduino Forum > Using Arduino > LEDs and Multiplexing > IRremote libary with 24keyRGB remote
arduino
Comments
Post a Comment