I have encountered a problem in my code for ESP8266 (NodeMCU), it's a code that uses IR transmitter to control a diode at the desired PWM level.
- void setup() {
- pinMode(D1, OUTPUT); //LED
- pinMode(D2, INPUT); // TSOP1738
- }
- void loop() {
- if (IrReceiver.decode()) {
- switch (IrReceiver.decodedIRData.decodedRawData) {
- case 1935591058:
- x +=y;
- analogWrite(D1, x);
- break;
- case 7520486194:
- x -=y;
- analogWrite(D1, x);
- break;
- }
- IrReceiver.resume();
- }
- Serial.println(x);
- delay(100);
- }
Once I comment out all analogWrite(); functions, the program accepts all signals and the value of x changes depending on the signal received. If the analogWrite(); function is present, IR signals are received until the analogWrite(); function is run.
I tried connecting the diode to all PWM pins, it behaves the same everywhere. I have also tried TSOP1738 on A0. No change.
On the AVR the same code works without problems. Why don't I use the AVR? Because it doesn't have PWM with 10bit resolution.
I have absolutely no idea how to solve this problem. Do you have a solution?
Second question, if this problem can't be solved with the conclusion that you simply can't receive IR signals and generate PWM at the same time on the ESP8266 board while you can on the AVR, will an I2C expander (e.g. PCA9685) solve this problem ?
Thank you!