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. Help with arrays and debouncing

Help with arrays and debouncing

Scheduled Pinned Locked Moved Development
11 Posts 4 Posters 4.7k Views 1 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.
  • DammeD Offline
    DammeD Offline
    Damme
    Code Contributor
    wrote on last edited by Damme
    #2

    I am not by a computer now but :

    define NUMCHILDREN sizeof(children)

    children = 8 chars.. :) you cant define that like so. The compiler will try to do a size of before code is compiled.

    The correct way would be uint8_t numchildren = sizeof(children); as your first line of code.
    and note, dont have a habit of using INT as standard (2 bytes, -32,768 to 32,767)

    YveauxY petewillP 2 Replies Last reply
    0
    • DammeD Damme

      I am not by a computer now but :

      define NUMCHILDREN sizeof(children)

      children = 8 chars.. :) you cant define that like so. The compiler will try to do a size of before code is compiled.

      The correct way would be uint8_t numchildren = sizeof(children); as your first line of code.
      and note, dont have a habit of using INT as standard (2 bytes, -32,768 to 32,767)

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

      @Damme no, that's not true....
      Children is an array of int. Sizeof(int) = 2, sizeof(children) = size of the whole structure = 8*sizeof(int) = 14

      I usually define a macro to get the number of elements in an array:
      #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

      Then use as:

      for(int I = 0; I < ARRAY_SIZE(children); ++I)
        ....
      

      http://yveaux.blogspot.nl

      DammeD petewillP 2 Replies Last reply
      0
      • YveauxY Yveaux

        @Damme no, that's not true....
        Children is an array of int. Sizeof(int) = 2, sizeof(children) = size of the whole structure = 8*sizeof(int) = 14

        I usually define a macro to get the number of elements in an array:
        #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

        Then use as:

        for(int I = 0; I < ARRAY_SIZE(children); ++I)
          ....
        
        DammeD Offline
        DammeD Offline
        Damme
        Code Contributor
        wrote on last edited by
        #4

        @Yveaux Hmm, you're right. I didsomething just the other day and realized that it was sizing the variable as a string, not the content of variable itself! and it was somthing like in this example.Hmm, too bad I didn't remenber correcly.. :)

        1 Reply Last reply
        0
        • YveauxY Yveaux

          @Damme no, that's not true....
          Children is an array of int. Sizeof(int) = 2, sizeof(children) = size of the whole structure = 8*sizeof(int) = 14

          I usually define a macro to get the number of elements in an array:
          #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

          Then use as:

          for(int I = 0; I < ARRAY_SIZE(children); ++I)
            ....
          
          petewillP Offline
          petewillP Offline
          petewill
          Admin
          wrote on last edited by
          #5

          @Yveaux said:

          I usually define a macro to get the number of elements in an array:

          #define ARRAY_SIZE(x)      (sizeof(x)/sizeof(x[0]))
          

          Great, thanks. Just so I'm clear, I would just paste in the line of code above as is? I don't need to substitute x for anything else?

          I was also just thinking... Is there any problem with having multiple Bounce objects in the array like I did?

          Thanks again. I'll try this tonight when I get home.

          My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

          1 Reply Last reply
          0
          • DammeD Damme

            I am not by a computer now but :

            define NUMCHILDREN sizeof(children)

            children = 8 chars.. :) you cant define that like so. The compiler will try to do a size of before code is compiled.

            The correct way would be uint8_t numchildren = sizeof(children); as your first line of code.
            and note, dont have a habit of using INT as standard (2 bytes, -32,768 to 32,767)

            petewillP Offline
            petewillP Offline
            petewill
            Admin
            wrote on last edited by
            #6

            @Damme said:

            and note, dont have a habit of using INT as standard (2 bytes, -32,768 to 32,767)
            

            Sorry forgot to respond to this before. What would you recommend I use instead, byte?

            Thanks.

            My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

            YveauxY 1 Reply Last reply
            0
            • petewillP petewill

              @Damme said:

              and note, dont have a habit of using INT as standard (2 bytes, -32,768 to 32,767)
              

              Sorry forgot to respond to this before. What would you recommend I use instead, byte?

              Thanks.

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

              @petewill said:

              What would you recommend I use instead, byte?

              uint8_t, which is effectively an unsigned char or byte.

              Bit more typing, but I prefer making things explicit.
              Also no discussion on the size if you ever decide to port your code to a different platform (regular int on ATMega is 8bit, Arduino defines it as 16bit, on 32bit intel x86 or e.g. Raspberry Pi it is 32bit and on 64bit intel x64 it is 64bit !!)

              http://yveaux.blogspot.nl

              1 Reply Last reply
              0
              • petewillP Offline
                petewillP Offline
                petewill
                Admin
                wrote on last edited by
                #8

                Ok, making progress. I think I have more problems than just my code. I am using a Mega so I can get more inputs and apparently I don't have something wired quite right. My sensors are sending 10 times but then stop because they are not receiving an Ack. That will then cause my node to time out. It seems I don't have the radio wired correctly. Any idea which pin is wrong? The sends are working fine when going to Vera (at least until the timeout). Here is what I'm getting in the serial monitor:

                    Relaying message back to gateway.
                    Tx: fr=12,to=0,la=12,ne=0,ci=21,mt=1,ty=16,cr=235: 0
                    Ack: receive timeout
                    Natalie's Door: 0
                    
                    Relaying message back to gateway.
                    Tx: fr=12,to=0,la=12,ne=0,ci=21,mt=1,ty=16,cr=140: 1
                    Ack: receive timeout
                    Natalie's Door: 1
                    
                    Relaying message back to gateway.
                    Tx: fr=12,to=0,la=12,ne=0,ci=21,mt=1,ty=16,cr=235: 0
                    Ack: receive timeout
                    Natalie's Door: 0
                    
                    Relaying message back to gateway.
                    Tx: fr=12,to=0,la=12,ne=0,ci=21,mt=1,ty=16,cr=140: 1
                    Ack: receive timeout
                    Open ping reading pipe: 12
                    Tx: fr=12,to=255,la=12,ne=255,ci=255,mt=4,ty=9,cr=85: 
                    No relay nodes was found. Trying again in 10 seconds.
                    Tx: fr=12,to=255,la=12,ne=255,ci=255,mt=4,ty=9,cr=85: 
                    No relay nodes was found. Trying again in 10 seconds.
                    Tx: fr=12,to=255,la=12,ne=255,ci=255,mt=4,ty=9,cr=85: 
                    No relay nodes was found. Trying again in 10 seconds.
                

                Thanks!

                My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                1 Reply Last reply
                0
                • petewillP Offline
                  petewillP Offline
                  petewill
                  Admin
                  wrote on last edited by
                  #9

                  Probably should have done some more testing before posting. Just anxious to get this working before I have to go to bed...

                  I figured out the problem. I had to put a capacitor across my radio 3.3v and ground pins. I haven't had to do this with any of my pro mini sensors so I forgot that may be an issue. Anyway, after doing that I got an Ack: received OK message!

                  Hopefully my mistakes can help someone else avoid them...

                  20140805_195725.jpg

                  My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                  1 Reply Last reply
                  0
                  • petewillP Offline
                    petewillP Offline
                    petewill
                    Admin
                    wrote on last edited by
                    #10

                    Ok, looks like I was wrong again. Turns out was a bad wire (or wires) connecting the radio to the Mega. Either that or the Mega has some bad connections. Anyway, I switched out the wires and all is working again (for now).

                    My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                    Z 1 Reply Last reply
                    0
                    • petewillP petewill

                      Ok, looks like I was wrong again. Turns out was a bad wire (or wires) connecting the radio to the Mega. Either that or the Mega has some bad connections. Anyway, I switched out the wires and all is working again (for now).

                      Z Offline
                      Z Offline
                      Zeph
                      Hero Member
                      wrote on last edited by
                      #11

                      @petewill said:

                      Ok, looks like I was wrong again. Turns out was a bad wire (or wires) connecting the radio to the Mega. Either that or the Mega has some bad connections. Anyway, I switched out the wires and all is working again (for now).

                      Loose wires are a bear to find at times - you do something (like adding a cap) and you think you fixed it. Then for no good reason the problem comes back. Been there.

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


                      37

                      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