logo elektroda
logo elektroda
X
logo elektroda

Wemos D1 mini / switch on output only for a certain time millis()

dominenator 1101 4
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16854505
    dominenator
    Level 11  
    Hello,
    I cannot tame the Wemos D1 mini in terms of millis(). I am trying to write a piece of code which, on receiving a command from the browser, turns on the output, in this case for testing purposes, of the "factory led" for 1 second, turns it off for 2sec and then on again for 3 seconds and then turns it off. I can't seem to get away with counting time. It is possible to take the easy way out and do a delay but at this point I will not be able to abort before the declared time has elapsed. Can I count on help with this?
    Below is what I have managed to scrape together.

    Code: C / C++
    Log in, to see the code
    .


    thanks in advance for your help :)
  • ADVERTISEMENT
  • #2 16855096
    krzbor
    Level 28  
    I don't really know how this is supposed to work. When you receive a "/ON" you call led1(). However, this is the only call and always with starttime=0. It may be enough in loop() to add a call to led1(), but I don't know if this would be too frequent. Individual conditions (e.g. (millis() - starttime) >= time1) will be continuously called. It is best to add some kind of state variable that will be set after a single condition check and block the next input.
  • ADVERTISEMENT
  • #3 16856052
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #4 16857379
    dominenator
    Level 11  
    I understand everything as much as possible. To blink a diode in a loop is no problem with a specific interval but how to trigger a series of blinks using after receiving "/ON". I am a beginner in this topic, so from your point of view trivial errors and trivial questions :) using delay the problem with millis disappears but another one appears, I can't stop the action because the program is suspended by delay ;) .

    Added after 39 [minutes]: .

    In short writing I would like to do something like this on millis.
    Code: C / C++
    Log in, to see the code
    .
  • #5 16857850
    krzbor
    Level 28  
    After all, I have written what needs to be done. Have you checked?
ADVERTISEMENT