Offline
Newbie
Karma: 0
Posts: 44
|
 |
« Reply #30 on: April 12, 2012, 03:02:18 pm » |
i opened that and i pushed the butten on my remote "1" and a second time the FFFFFFF in between was because i pushed them to fast 8B73AC5 FFFFFFFF 8B73AC5
|
|
|
|
|
Logged
|
|
|
|
|
Colorado
Offline
Edison Member
Karma: 41
Posts: 1262
Reviving dead brain cells with Arduinos.
|
 |
« Reply #31 on: April 12, 2012, 04:47:46 pm » |
Well yeah, your cmd_one() and cmd_two() are identical, so regardless of which button you push, it's doing the same thing. So change one of them to do something else. Right now you have both of them fading an LED up and down again.
Also, you need to understand that as long as 'num' does not change, the LED will continue to fade on and off indefinitely. That's how you have it coded (which was the example I gave you too.) So basically what happens is this: You push a button, and it registers as either num = 1 or num = 2. At that point the LED will start to fade on and off. If you don't do anything after that, it will continue to fade on and off. It's not till you push another button that causes 'num' to change value, will it do something else.
If that's not the desired result, then you need to explain more about what you want them to do. From the beginning, from the moment you push a button.
|
|
|
|
|
Logged
|
|
|
|
|
Colorado
Offline
Edison Member
Karma: 41
Posts: 1262
Reviving dead brain cells with Arduinos.
|
 |
« Reply #32 on: April 12, 2012, 04:56:22 pm » |
Change your current cmd_one(0 and cmd_two() functions for these two, see what happens: void cmd_one() { // langzaam analogWrite(9, brightness); brightness = brightness + fadeAmount; if (millis() - lastRun > 150) { if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } lastRun = millis(); } }
void cmd_two() { // vlug analogWrite(9, brightness); brightness = brightness + fadeAmount; if (millis() - lastRun > 25) { if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } lastRun = millis(); } } What happens now?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 44
|
 |
« Reply #33 on: April 13, 2012, 05:41:08 am » |
if i push button "1" once the led on pin 9 lights up in his lowest setting and does notthing. he does't become brighter. but when i push an other button of my remote (or even a button of a romote i never used) the led goes a bit brighter (only a little bit.) so i think there ar 2 problems: he does resume to check if there are signals (otherwise the wouldn't happen anything, i think) but hie doesn't cair about the if statment in the void loop. and he doesn't repeat cmd_one() or cmd_two() you also said You push a button, and it registers as either num = 1 or num = 2. At that point the LED will start to fade on and off. If you don't do anything after that, it will continue to fade on and off. It's not till you push another button that causes 'num' to change value, will it do something else.
If that's not the desired result, then you need to explain more about what you want them to do. From the beginning, from the moment you push a button. what i try to create is a programme for a rgb ledstrip that can dim a color independently (in this i've more or less succeded, this i think i can handle), but what i don't know is how to do the following: push button 1, collors begin to fade (in a certain order, not random), push button 2 (for example) a trafic light, and so on, but al these go on if ther is no other command recieved, for example with button 1: red fades on, then green fades on then red fades off and blue fades on , green fades off , red fades on and blue fades off and this should be repeated unless these is an other command. i am using here only pin 9 to make every thing less dificult, so i think num has to remain 1 (for ever) Unless it gets an outher command that sais num hes to be an other value sorry that is repeat myself so muth but does it make sence?
|
|
|
|
« Last Edit: April 13, 2012, 05:59:39 am by timothysg1 »
|
Logged
|
|
|
|
|
Colorado
Offline
Edison Member
Karma: 41
Posts: 1262
Reviving dead brain cells with Arduinos.
|
 |
« Reply #34 on: April 13, 2012, 11:38:32 am » |
Try this: Connect one LED on pin 9, and another on pin 10. Then use these two functions: void cmd_one() { // langzaam if (millis() - lastRun > 150) { analogWrite(9, brightness); brightness = brightness + fadeAmount; if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } lastRun = millis(); } }
void cmd_two() { // vlug if (millis() - lastRun > 25) { analogWrite(10, brightness); brightness = brightness + fadeAmount; if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } lastRun = millis(); } } And your loop has an error in it, you put do_task() inside of the if statement, it needs to be outside of it so it's constantly running. Here's a revised version: void loop() { // check for incoming RF data if (irrecv.decode(&results)) { Serial.println(results.value, HEX); if (results.value==0x8B73AC5) { num = 1 ; } if (results.value==0x8B77887) { num = 2 ; } irrecv.resume(); } do_task(num); } Once you have that in place, with the two LEDs, pressing button 1 should make the LED on pin 9 fade on and off constantly. Pressing button 2 should switch to the LED on pin 10. Now, you will notice that when you press a different button, it instantly stops whatever it was doing with the previous LED, so you may end up with one LED turned on, while the other is fading on and off. Don't worry about it for now, this is just a test, see if you can even get the individual buttont on your remote to actually address two different LEDs.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 44
|
 |
« Reply #35 on: April 15, 2012, 05:25:27 am » |
thats exactly what happens, i tried some other buttons on my remote to see if there is an unexpected reaction, and ther isn't any, so far so good. What now?
|
|
|
|
|
Logged
|
|
|
|
|
Colorado
Offline
Edison Member
Karma: 41
Posts: 1262
Reviving dead brain cells with Arduinos.
|
 |
« Reply #36 on: April 15, 2012, 12:58:40 pm » |
Well, the rest is up to you. I gave you the building blocks for driving two separate LEDs on two separate pins, using two separate buttons on your remote. You can fold the actions back to a single pin in which case you will only be controlling one LED, but letting it do two different things ( cmd_one() or cmd_two() ). Either way, the sky is the limit at this point. There are many way to do what you're trying to accomplish, you just have to keep playing, testing, but most of all, have fun with it.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 44
|
 |
« Reply #37 on: April 18, 2012, 09:21:13 am » |
one last thing, the line lastRun = millis(); does it does sommething, is that what the delay resambles, or is it only because it's neccesary for the code?
|
|
|
|
|
Logged
|
|
|
|
|
Colorado
Offline
Edison Member
Karma: 41
Posts: 1262
Reviving dead brain cells with Arduinos.
|
 |
« Reply #38 on: April 18, 2012, 02:53:49 pm » |
You're using 'lastRun' to check the elapsed time. Remember this line: if (millis() - lastRun > 150) { That is where it gets used. You're taking the current elapsed time from millis(), subtracting lastRun and seeing if the result is bigger than '150'. So 'lastRun' must be set each time a loop runs. Otherwise it will never reset.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 44
|
 |
« Reply #39 on: April 20, 2012, 12:24:06 am » |
i dont understaand why it doesn"t FULLY execute cmd_one #include "IRremote.h" #include "IRremoteInt.h"
int num;
long lastRun; int RECV_PIN = 0; // pin0 =linker poot reciever, middenste poot reciever= 5V, rechter poot reciever =grd velleman:IR38DM IRrecv irrecv(RECV_PIN); decode_results results;
int brightnessR = 0; // how bright the RED LED is int fadeAmountR = 5;
int brightnessG = 0; // how bright the GREEN LED is int fadeAmountG = 5;
int brightnessB = 0; // how bright the BLUE LED is int fadeAmountB = 5;
void setup() { pinMode(9, OUTPUT); //R pinMode(10, OUTPUT); //G pinMode(11, OUTPUT); //B Serial.begin(9600); irrecv.enableIRIn(); }
void cmd_one() { // langzaam if (millis() - lastRun > 150) { analogWrite(9, brightnessR); analogWrite(10, brightnessG); analogWrite(11, brightnessB); brightnessR = brightnessR + fadeAmountR; // red fades on (works fine) if (brightnessR == 255 && brightnessB == 0) { fadeAmountR = -fadeAmountR ; // red fades off (works fine) brightnessG = brightnessG + fadeAmountG; // green fades on (goes on a bit but not completely) } if (brightnessG == 255 && brightnessR == 0) { fadeAmountG = -fadeAmountG ; //green fades on (doesn't work) brightnessB = brightnessB + fadeAmountB; // Blue fades one(doesn't work) } if(brightnessB == 255 && brightnessG == 0){ fadeAmountB = -fadeAmountB; // blue fades off(doesn't work) } lastRun = millis(); } }
void cmd_two() { // vlug if (millis() - lastRun > 25) { analogWrite(10, brightnessG); brightnessG = brightnessG + fadeAmountG; if (brightnessG == 0 || brightnessG == 255) { fadeAmountG = -fadeAmountG ; } lastRun = millis(); } }
void do_task(int num) { switch (num) { case 1: cmd_one(); break; case 2: cmd_two(); break; } }
void loop() { // check for incoming RF data if (irrecv.decode(&results)) { Serial.println(results.value, HEX); if (results.value==0x8B73AC5) { num = 1 ; } if (results.value==0x8B77887) { num = 2 ; } irrecv.resume(); } do_task(num); }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #40 on: April 20, 2012, 05:02:52 am » |
void cmd_one() { // langzaam if (millis() - lastRun > 150) { analogWrite(9, brightnessR); analogWrite(10, brightnessG); analogWrite(11, brightnessB); brightnessR = brightnessR + fadeAmountR; // red fades on (works fine) if (brightnessR == 255 && brightnessB == 0) { Get rid of the tab characters and use spaces.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 44
|
 |
« Reply #41 on: April 20, 2012, 05:12:59 am » |
hier you go #include "IRremote.h" #include "IRremoteInt.h"
int num;
long lastRun; int RECV_PIN = 0; // pin0 =linker poot reciever, middenste poot reciever= 5V, rechter poot reciever =grd velleman:IR38DM IRrecv irrecv(RECV_PIN); decode_results results;
int brightnessR = 0; // how bright the RED LED is int fadeAmountR = 5;
int brightnessG = 0; // how bright the GREEN LED is int fadeAmountG = 5;
int brightnessB = 0; // how bright the BLUE LED is int fadeAmountB = 5;
void setup() { pinMode(9, OUTPUT); //R pinMode(10, OUTPUT); //G pinMode(11, OUTPUT); //B Serial.begin(9600); irrecv.enableIRIn(); }
void cmd_one() { // langzaam if (millis() - lastRun > 150) { analogWrite(9, brightnessR); analogWrite(10, brightnessG); analogWrite(11, brightnessB); brightnessR = brightnessR + fadeAmountR; // red fades on (works fine) if (brightnessR == 255 && brightnessB == 0) { fadeAmountR = -fadeAmountR ; // red fades off (works fine) brightnessG = brightnessG + fadeAmountG; // green fades on (goes on a bit but not completely) }
if (brightnessG == 255 && brightnessR == 0) { fadeAmountG = -fadeAmountG ; //green fades on (doesn't work) brightnessB = brightnessB + fadeAmountB; // Blue fades one(doesn't work) } if(brightnessB == 255 && brightnessG == 0){ fadeAmountB = -fadeAmountB; // blue fades off(doesn't work) } lastRun = millis(); } }
void cmd_two() { // vlug if (millis() - lastRun > 25) { analogWrite(10, brightnessG); brightnessG = brightnessG + fadeAmountG; if (brightnessG == 0 || brightnessG == 255) { fadeAmountG = -fadeAmountG ; } lastRun = millis(); } }
void do_task(int num) { switch (num) { case 1: cmd_one(); break; case 2: cmd_two(); break; } }
void loop() { // check for incoming RF data if (irrecv.decode(&results)) { Serial.println(results.value, HEX); if (results.value==0x8B73AC5) { num = 1 ; } if (results.value==0x8B77887) { num = 2 ; } irrecv.resume(); } do_task(num); }
|
|
|
|
« Last Edit: April 20, 2012, 05:15:01 am by timothysg1 »
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #42 on: April 20, 2012, 11:40:31 pm » |
I can't see anything obvious, but I suggest you put some serial prints in to show what is happening. With labels.
eg.
"cmd_two".
"brightnessG was 5".
"brightnessG is now 10".
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 44
|
 |
« Reply #43 on: April 21, 2012, 07:18:06 am » |
is there a way to let the arduino software print those? otherwise i do it on pure observation
|
|
|
|
|
Logged
|
|
|
|
|
Colorado
Offline
Edison Member
Karma: 41
Posts: 1262
Reviving dead brain cells with Arduinos.
|
 |
« Reply #44 on: April 21, 2012, 02:24:34 pm » |
if (brightnessR == 255 && brightnessB == 0) { fadeAmountR = -fadeAmountR ; // red fades off (works fine) brightnessG = brightnessG + fadeAmountG; // green fades on (goes on a bit but not completely) }
This test TRUE only once. So brightnessG is incremented only once. Think about it, you're testing when brightnessR == 255 and when that's TRUE, you flip the value of fadeAmountR. At the next cycle, brightnessR is no longer 255, so it will never enter that loop again. BrightnessG never gets incremented after that.
|
|
|
|
|
Logged
|
|
|
|
|
|