Closed pvint closed 3 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);
.
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);
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);
}
...
}
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?
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.