Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. [SOLVED] very wierd sleep behaviour

[SOLVED] very wierd sleep behaviour

Scheduled Pinned Locked Moved Development
9 Posts 3 Posters 1.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • rozpruwaczR Offline
    rozpruwaczR Offline
    rozpruwacz
    wrote on last edited by Yveaux
    #1

    this is my loop function:
    #define MY_LED 19
    #define BUTTON_PIN 2
    bool led = false;
    void loop()
    {
    sleep(1000);
    digitalWrite(MY_LED, led);
    led = !led;
    sleep(digitalPinToInterrupt(BUTTON_PIN), FALLING, 10000);
    }

    this should turn the led on/of in 11s intervals or after button press. But it turn led on/off in 1s intervals !? if I comment the call to first sleep, then it works as expected (turns the led on/off in 10s intervals). So is that possible ? Is this a bug ? I'm using 2.1.1 MySensors library.

    1 Reply Last reply
    0
    • rozpruwaczR Offline
      rozpruwaczR Offline
      rozpruwacz
      wrote on last edited by
      #2

      if I change
      sleep(1000);
      to
      sleep(digitalPinToInterrupt(BUTTON_PIN), FALLING, 1000);
      then works ok ... this must be a bug ...

      1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by gohan
        #3

        Use wait instead of sleep in loop, use sleep at the end of loop. But why are you not just using sleeping for 11s at the end of loop? Some people used like wait (500) before the sleep call to avoid random interrupts.
        Maybe you could set the pull up resistor on pin 2 just to avoid floating pin randomly triggering interrupt

        1 Reply Last reply
        0
        • rozpruwaczR Offline
          rozpruwaczR Offline
          rozpruwacz
          wrote on last edited by rozpruwacz
          #4

          do You mean that the sleep function may be called only once at the end of the loop function ? Could You point me to the docs where it is stated ?

          1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #5

            Just look at the many examples around, sleep is used at the end of loop function because it puts everything in power saving mode. In your case it depends if you want to have a 1s delay after button is pressed or not and have just the sleep function at the end doing the timing

            1 Reply Last reply
            0
            • rozpruwaczR Offline
              rozpruwaczR Offline
              rozpruwacz
              wrote on last edited by rozpruwacz
              #6

              examples are not the documentation. The question is, why the first sleep function causes the other one to stop sleeping immediately ? It shouldn't do that. The BUTTON_PIN has of course the pullup, so it is not triggering the actual interrupt.

              YveauxY 1 Reply Last reply
              0
              • rozpruwaczR rozpruwacz

                examples are not the documentation. The question is, why the first sleep function causes the other one to stop sleeping immediately ? It shouldn't do that. The BUTTON_PIN has of course the pullup, so it is not triggering the actual interrupt.

                YveauxY Offline
                YveauxY Offline
                Yveaux
                Mod
                wrote on last edited by
                #7

                @rozpruwacz recently an issue with waking from interrupts was fixed in the mySensors library code.
                Try with the development version of the library (2.2.0 beta) and report back if that fixes your issue.

                http://yveaux.blogspot.nl

                1 Reply Last reply
                0
                • rozpruwaczR Offline
                  rozpruwaczR Offline
                  rozpruwacz
                  wrote on last edited by
                  #8

                  YES ! beta version has no more that issue, thaks ! :)

                  YveauxY 1 Reply Last reply
                  1
                  • rozpruwaczR rozpruwacz

                    YES ! beta version has no more that issue, thaks ! :)

                    YveauxY Offline
                    YveauxY Offline
                    Yveaux
                    Mod
                    wrote on last edited by
                    #9

                    @rozpruwacz great to hear!
                    Now continue the fun :laughing:

                    http://yveaux.blogspot.nl

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    17

                    Online

                    11.7k

                    Users

                    11.2k

                    Topics

                    113.1k

                    Posts


                    Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • MySensors
                    • OpenHardware.io
                    • Categories
                    • Recent
                    • Tags
                    • Popular