vintlabs / fauxmoESP

Add voice control of your ESP32 and ESP8266 devices using Amazon Alexa
MIT License
383 stars 69 forks source link

Reverse inverse logic #74

Closed pvint closed 3 years ago

pvint commented 5 years ago

Original report by Deiu (Bitbucket: d3iu, GitHub: d3iu).


Hi, i need some help getting the program to work in normal mode, i mean invert the reverse logic, because i need to say ALEXA SWICH OFF for it to turn ON and viceversa! Also i would like if it could be possible in another instance to make some modification so i can attach the program to my computer so... the relay must go on for a second , delay half of second and then off... but that in a separate code, i want to make 2 devices and one of them to put inside my computer so i can turn it on with my voice and the other one for the monitor.

pvint commented 5 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


Just change the digitalWrite call inside the onSetState callback so it says digitalWrite(LED, state);.

pvint commented 5 years ago

Original comment by Deiu (Bitbucket: d3iu, GitHub: d3iu).


Xose Pérez Thank you for your help and work. it`s great! Can you please tell me what to edit to make the code turn on for a second then delay and then off again, like a pulse for pc button...? will this work ?

digitalWrite(LED, state); delay(5); digitalWrite(LED, !state);

pvint commented 5 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


Do not add delay inside a callback. Instead, set a flag there and then manage the pulse from somewhere else. Alternatively you can use the Ticker library to set a turnoff event from within the callback, like this (not tested):


Ticker tick;

void setLEDState(bool state) {
    digitalWrite(LED, state);
}

void setup() {

...

fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
    setLEDState(true);
    tick.once(1, setLEDState, false);
}

...

}
pvint commented 5 years ago

Original comment by Mohd Almajed (Bitbucket: Almajed, GitHub: Almajed).


Hi Xose

Im having the same reverse action issue with alexa.

I tried to change the digitalwrite to digitalWrite(LED, state); But it wont compile.

Can you explain how to solve it?

pvint commented 5 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


What error do you get when trying to compile it?

pvint commented 5 years ago

Original comment by Mohd Almajed (Bitbucket: Almajed, GitHub: Almajed).


Sorry but the problem was solved

it was digitalWrite(LED, !state);

as you said i changed it to digitalWrite(LED, state);

the problem was the "!"

Thanks alot