I have looked into this a bit more and the cause for the Assertion Failure (SOS+14) seems to come from the fact that the library hooks up a timer interrupt which calls digitalRead()before setting the pinMode() to INPUT.
Obviously one of the recent releases enforces the need to explicity set pinMode() before using digitalRead() (at least in an ISR) although INPUT is the default GPIO state.
Have you tried if it works. If so, where in the code do you set the pinMode()? Just asking because getting my photon working after the sos+14 was a pain.
I have not tried whether the IR part works but the SOS panic crash went away and that was enough for my part. Unfortunately @matej_konecny never reported back whether this actually solved his issue.
However, the obvious place without having to change the library would be in setup() before using any of the IRRemote functions.
Unfortunately @mdoan7 has not reacted yet to the issue filed here
I’d suggest you rather use A1 instead of 11 in the pinMode() call.
While it might be common practice in Arduino code to use the anonymous pin numbers, in the Particle ecosystem we encourage people to use the pin labels for clarity.
There are always macro definitions that do the label/pin-number mapping for you.
While it’s unlikely that pin numbers change using the labels would still keep you safe.
Particularly between device generations the pin numbers might not always match, but that extra level of abstraction (hardware agnosticism) helps writing more portable code.
True. Changed that as well. Not sure if I should start a new topic but i have another question. I have been tinkering with my ledstrip remote and tv remote successfully so that i pass a string (on, off, vol+, vol- etc) to a cloudfunction via particle app on my phone. The function uses an if else statement to check the string and act accordingly (transmit ir signal to my device). Works beautifully.
Would it be better/simpler to use a switch-case statement instead? Is it possible and what would that look like?
With a switch() statement you cannot cover strings but only ordinal types (i.e. numeric types).
However, I have often proposed an entirely different approach with the focus of maintainability and extensibility
struct IrCmd_t {
char command[8];
uint32_t code;
};
const IrCmd_t commands[] =
{ { "off" , 0x20DF10EF }
, { "1" , 0x20DF8877 }
, { "2" , 0x20DF48B7 }
, { "-" , 0x20DFC03F }
, { "+" , 0x20DF40BF }
};
const int cmdCount = sizeof(commands) / sizeof(commands[0]); // derive command count from "dynamic" array
int button(const char* cmd) {
for(int i = 0; i < cmdCount; i++) { // traverse commands list
if (!strcmp(commands[i].command, cmd)) { // do we have a match?
irsend.sendNEC(commands[i].code, 32); // emit the respective command code
return i; // return the index of the found command
}
}
return -1; // no match found
}
To add a new command just add another line to the array declaration and the rest is taken care of already.
Even when you stick with your if() ... else if() ... else scheme a useful habit to adopt is that you should not return just any arbitrary value but rather think of some useful value to return to get some feedback about the inner state of the called function.
That is great. Looks neat and the extensibility is a big plus. However I get many error messages. Even if I understand the basics of both the code and the error messages, it is still above my knowledge.