Go Down

Topic: LED fade will not listen to IR input for interupt. (Read 3 times) previous topic - next topic

AWOL

Quote
This calls the loop() function.  What is that all about ?

It's all about heartache and hair-loss, that's what it's about.
Even well-controlled recursion is risky on a RAM-limited micro.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UKHeliBob

Have you seen the dictionary definition of recursion ?

"See recursion"
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

MrKovacic


If I am reading your code right you have

Code: [Select]
attachInterrupt(pbIn, CheckYellow, HIGH);

pbIn is set to 0 so I interpret that as "call the CheckYellow function when the pin associated with interrupt 0 is HIGH"
Although I freely admit that I am not familiar with interrupts, reading the reference pages I see that interrupt 0 is associated with pin 2 and that the possible values of the third parameter of attachInterrupt() are LOW, CHANGE, RISING OR FALLING.

Have you got anything attached to pin 2 ?
What will happen with the parameter set to HIGH ?

If the interrupt ever causes the CheckYellow function to be called

Code: [Select]
void CheckYellow() {
  if (results.value           == 0x96B47 ) {
    loop();
  }
}

This calls the loop() function.  What is that all about ?

Your code won't compile for me because I don't have the library but there are also other errors reported

Code: [Select]
sketch_jan16a:69: error: 'IRrecv' does not name a type
sketch_jan16a:70: error: 'decode_results' does not name a type
sketch_jan16a.ino: In function 'void setup()':
sketch_jan16a:76: error: 'irrecv' was not declared in this scope
sketch_jan16a.ino: In function 'void loop()':
sketch_jan16a:80: error: 'irrecv' was not declared in this scope
sketch_jan16a:80: error: 'results' was not declared in this scope
sketch_jan16a.ino: In function 'void CheckYellow()':
sketch_jan16a:184: error: 'results' was not declared in this scope
sketch_jan16a.ino: In function 'void getIR()':
sketch_jan16a:211: error: 'IRrecv' was not declared in this scope
sketch_jan16a:211: error: expected `;' before 'irrecv'
sketch_jan16a:212: error: 'decode_results' was not declared in this scope
sketch_jan16a:212: error: expected `;' before 'nresults'


Your code has got so mangled through attempts to fix problems that it is practically unreadable.  Can I suggest that you create an example of what you want to do, keeping it as simple as possible as I for one cannot see the wood for the trees.


It actually compiles for me with no errors, and it may be because I have extra libraries. Also, I am using compiler version 1.0.1 , not sure if that helps. As far as the interrupt, I have the output pin of the IR receiver going to pin 2, which in a perfect world would register as HIGH the moment I hit a button on the remote. I am trying to keep the interrupt code small, so I wanted it to check and decode looking for only one value, the yellow button.

I tried cleaning the code using some autoit apps I came across, but it keeps stripping out needed operators. I don't have any formal programming training, so this is kind of thrown together by an amateur ;)

As for the WHILE after the IF statement, the only reason I have that is because it will only execute the pattern once and stop otherwise. When I added WHILE, it actually loops the pattern which is what I was going for.

UKHeliBob

Even with the IRremote library it will not compile for me.  Does the IRremote library depend on others ?

You say that "I have the output pin of the IR receiver going to pin 2"  I cannot see where that is defined in your code, nor can I see a pinMode definition for pin 2.  Have I missed it ?

Cleaning the code with an an autoit app sounds like a nightmare.  Was it written specifically to tidy Arduino code ? What does it try to do ?  Putting each brace on its own line would be a start I suppose.

I don't know what you mean about the WHILE after the IF.  I was questioning calling loop() from the CheckYellow() function though.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

MrKovacic



You say that "I have the output pin of the IR receiver going to pin 2"  I cannot see where that is defined in your code, nor can I see a pinMode definition for pin 2.  Have I missed it ?



I was pulling from http://arduino.cc/en/Reference/AttachInterrupt

If I understand it, int.0 is supposed to point to pin 2 on the Arduino Mega. Essentially, i wanted it to perform this logic:

While in the fade, if you see any change in activity on pin2 which is also connected to the emitter of the IR REC, then determine what code is being sent. If the code is the same as my yellow button, then you can jump out of what you are doing, and go back to the loop.

As for the includes, I will get a list of includes i have on my laptop at home and let you know.

My mental logic which is flawed (because if it wasn't, then this would work) indicated that having an interrupt could call this:

Code: [Select]

void CheckYellow() {
  if (results.value           == 0x96B47 ) {
    loop();
  }
}


to execute the intended logic above.  I'm sure you can see where I am trying to go with it, I just cant fin that little nitch that would actually make it work. Once I get past this hurdle, I can grow the code to all new heights.

The reason the code looks so complicated is i have so many declarations, it looks like they make up half the script. At the moment, there are 2 fade options, one simple, one complex and configurable. It also has a blink what works exactly as designed, because it uses BlinkWithoutDelay with a built in adjustable speed to make it blink faster or slower based on IR volume buttons up and down, which works great.

I took the fader scripts and tried to remove the delay() and substitute it with the BlinkWithoutDelay method which works great, only during the fade calculations, the IR receiver is ignored, and I am thinking this is because it is busy making calculations, or, it does not see enough reason to interrupt the code and take me back to ground zero in the code.

Go Up