One thing that stuck out to me was the lack of a return
statement in your estado_funcion()
.
If you were using device OS version 2.0.0 I’d have expected your device to go into an SOS panic crash. But since you are not reporting such a thing, there may be other things wrong.
On the other hand, the code you posted is also lacking multiple function definitions which also suggests that’s not the exact code you are compiling, otherwise you’d also get loads of error messages as I did.
The next thing I noticed that you don’t actually use the IRremoteLearn
library but rather do the bit banging yourself.
There is nothing wrong with that in itself, but then it would be good to remove any distractions from your code.
Additionally I’d let the PWM hardware on the Photon do some of the heavy lifting
Along that line you could give this alternative approach a try
// let the PWM hardware do the heavy lifting (IRledPin needs to be PWM enabled e.g. D3)
void pulseIR(uint32_t pulse, uint32_t gap = 0) { // using 38kHz PWM
analogWrite(IRledPin, 127, 38000); // start PWM with 50% duty cycle
delayMicroseconds(pulse);
digitalWrite(IRledPin, LOW); // off
delayMicroseconds(gap);
}
void APAGARAIRE() {
pulseIR(9320, 4580);
pulseIR( 700, 1660);
pulseIR( 660, 580);
pulseIR( 660, 580);
pulseIR( 680, 560);
pulseIR( 660, 580);
pulseIR( 680, 560);
pulseIR( 660, 1720);
pulseIR( 680, 560);
pulseIR( 660, 1700);
pulseIR( 700, 0);
}
Finally, your style in estado_function()
could benefit from a different indentation scheme like this
int estado_funcion(String recibido) {
int retVal = __LINE__ * -1; // indicate an invalid choice by a negative line number (also tells you the base line for valid ones)
if(recibido == "EncenderM") { // INICIO GHIA
retVal = __LINE__; // to indicate which branch was executed return the line number
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
ENCENDERAIRE();
}
else if(recibido == "ApagarM") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
APAGARAIRE();
}
else if(recibido == "SubirG") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
SUBIRG();
}
else if(recibido == "BajarG") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
BAJARG();
} //FIN GHIA
else if(recibido == "EncenderL") { //INICIO LANIX
retVal = __LINE__;
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
ENCENDERL();
}
else if(recibido == "ApagarL") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
APAGARL();
}
else if(recibido == "SubirL") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
SUBIRL();
}
else if(recibido=="BajarL") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
BAJARL();
} //FIN LANIX
else if(recibido == "EncenderM") { //INICIO MAC
retVal = __LINE__;
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
ENCENDERM();
}
else if(recibido == "ApagarM") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
APAGARM();
}
else if(recibido == "SubirM") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
SUBIRM();
}
else if(recibido == "BajarM") {
retVal = __LINE__;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
BAJARM();
} //FIN MAC
return retVal;
}
which makes reading somewhat easier.
However, I’d do the whole thing even more concise and more maintainable IMO.
The same behavour could easily be coded in less than 60 lines.
BTW, we also need to keep the Android side and the Photon firmware separated.
What Android app are you talking about?
Currently we’d only focus on the firmware and to exclude any contribution to the issue from the Android app you may either want to use the Particle Tinker App, console.particle.io/devices or CLI to test the functionality of the firmware.