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. Troubleshooting
  3. Increse/Decrese a value with a button

Increse/Decrese a value with a button

Scheduled Pinned Locked Moved Troubleshooting
13 Posts 5 Posters 1.2k Views 4 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.
  • dzjrD dzjr

    Hello MySensors friends,

    I am working on making a thermostat for my shed, in general it already works.
    I use two set points, one as frost protection, 5 degrees C, and a second one if I want to work in the shed.

    To change the set points I use two push buttons, and I can also operate it via the controller so that the heating can be set higher without having to go to the shed.
    This all works, it is still in parts / breadboards on my desk for testing.

    Now I would like to make an extra function where I can manually increase or decrease the 2nd setpoint (high setpoint).

    I have already tried many things and I have the problem that the setpoint goes sky-high until I release the button, so not just one degree up or down .....

    What have I tried:
    input both with digitalread and with a debouncer, both have the same effect.

    -if (SetHigher == HIGH) {
    Setpoint2 ++;
    }
    
    -if (SetHigher == HIGH) {
    Setpoint2 + = 1;
    }
    
    -if (SetHigher! = SetHigherOld) {
    Setpoint2 ++;
    (SetHigherOld = SetHigher);
    }
    
    
    -if SetHigher == HIGH && SetHigherOld == 0) {
    SetHigherOld = 1;
    Setpoint2 ++;
    wait (1)
    SetHigherOld = 0;
    }
    

    and many other possibilities.
    Some times it resulted in no increase or decrease at all, but mostly in the gigantic increase or decrease of the set point.

    To be honest, I am about to give up now, I have tried all options on different forums, but without result.

    It is not a MySensors problem, that part just works, so do the other functions, just raising or lowering the setpoint a few degrees does not work ...

    The entire sketch is more than 800 lines long (I also connected an LCD 1602), so probably some overkill to post it here.

    I use an Arduino Uno for testing.

    Who knows maybe a tip, or perhaps the solution for this challenge?

    Thanks in advance!

    !! EDITED at request of @dbemowsk !!

    dbemowskD Offline
    dbemowskD Offline
    dbemowsk
    wrote on last edited by
    #4

    @dzjr Can you edit your post to put your code in a code block. When you edit the post, highlight your code section and then click on the </> icon. Also, your code seems a little odd to me. You have for example

    if (SetHigher == HIGH) {
    (Setpoint2 ++);}
    

    I would write that like this

    if (SetHigher == HIGH) {
        Setpoint2 ++;
    }
    

    No need to put parenthesis around your "Setpoint2 ++".

    @mfalkvidd He did say "input both with digitalread and with a debouncer, both have the same effect.", though I'm not sure what kind of debouncer he tried.

    Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
    Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

    1 Reply Last reply
    0
    • dzjrD Offline
      dzjrD Offline
      dzjr
      wrote on last edited by
      #5

      @dbemowsk i did edited the original post as you asked.

      dbemowskD 1 Reply Last reply
      2
      • dzjrD dzjr

        @dbemowsk i did edited the original post as you asked.

        dbemowskD Offline
        dbemowskD Offline
        dbemowsk
        wrote on last edited by
        #6

        @dzjr Thank you. Many here will appreciate that as it makes it much easier to read.

        Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
        Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

        1 Reply Last reply
        0
        • electrikE Offline
          electrikE Offline
          electrik
          wrote on last edited by electrik
          #7

          You now increase as long as the button is pressed, you should only increase on pressing the button. So you should check if the button has changed, and if it does increase the thermostat value

          So something like

          button = digitalRead (pin);
          if (button != OldButton)
          {
            Value++;
            OldButton = button;
          }
          
          dzjrD 1 Reply Last reply
          0
          • electrikE electrik

            You now increase as long as the button is pressed, you should only increase on pressing the button. So you should check if the button has changed, and if it does increase the thermostat value

            So something like

            button = digitalRead (pin);
            if (button != OldButton)
            {
              Value++;
              OldButton = button;
            }
            
            dzjrD Offline
            dzjrD Offline
            dzjr
            wrote on last edited by dzjr
            #8

            @electrik

            I even tried that, and it's still sky high

            the code i made is :

            int SetHigher == digitalRead(Higher_PIN);
            int SetHigherOld ;
            
            if (SetHigher != SetHigherOld)
            {
            Heating_set_High ++;
            SetHigherOld = SetHigher;
            }
            
            

            Also tried boolean for digitaRead.

            !!! EDIT, changed the code !!!

            zboblamontZ electrikE 2 Replies Last reply
            0
            • dzjrD dzjr

              @electrik

              I even tried that, and it's still sky high

              the code i made is :

              int SetHigher == digitalRead(Higher_PIN);
              int SetHigherOld ;
              
              if (SetHigher != SetHigherOld)
              {
              Heating_set_High ++;
              SetHigherOld = SetHigher;
              }
              
              

              Also tried boolean for digitaRead.

              !!! EDIT, changed the code !!!

              zboblamontZ Offline
              zboblamontZ Offline
              zboblamont
              wrote on last edited by
              #9

              @dzjr Delay incrementing via a while loop with 50-500ms sleep/wait, to check the button has changed state before proceeding. Modify delay value to suit.

              1 Reply Last reply
              1
              • dzjrD dzjr

                @electrik

                I even tried that, and it's still sky high

                the code i made is :

                int SetHigher == digitalRead(Higher_PIN);
                int SetHigherOld ;
                
                if (SetHigher != SetHigherOld)
                {
                Heating_set_High ++;
                SetHigherOld = SetHigher;
                }
                
                

                Also tried boolean for digitaRead.

                !!! EDIT, changed the code !!!

                electrikE Offline
                electrikE Offline
                electrik
                wrote on last edited by
                #10

                @dzjr

                you are reading the pin into SetHigher first, which is good.
                Then you are setting SetHigherOld to a value which is negative, so always different from SetHigher. So that is always true. I also don't see how a negative value can fit into a boolean.

                I now see I made a mistake in my previous post. I'll update it.

                dzjrD 1 Reply Last reply
                0
                • electrikE electrik

                  @dzjr

                  you are reading the pin into SetHigher first, which is good.
                  Then you are setting SetHigherOld to a value which is negative, so always different from SetHigher. So that is always true. I also don't see how a negative value can fit into a boolean.

                  I now see I made a mistake in my previous post. I'll update it.

                  dzjrD Offline
                  dzjrD Offline
                  dzjr
                  wrote on last edited by
                  #11

                  @electrik
                  Thank you all for the help!

                  It's working!!!'

                  I have done the following;

                  at the top:

                  float Heater_set_High = 17;
                  float Change_Degree = 0.5;
                  unsinged long SetHigherOld = 0;
                  unsinged long SetLowerOld = 0;
                  

                  i used 0,5 becouse than the change of de setpoint is changed by 1 when you press the button.

                  The reading from te button i do with the debouncer (SetHigher & SetLower)

                  The sketch:

                  if (SetHigher !=SetHigherOld){
                  Heater_set_High += ChangeDegree;
                  SetHigherOld = SetHigher;
                  }
                  
                  if (SetLower !=SetLowerOld){
                  Heater_set_High -= ChangeDegree;
                  SetLowerOld = SetLower;
                  }
                  
                  // To protect te setpoint going to high i made this:
                  
                  if (Heater_set_High >= 25){
                  Heater_set_High = 25;
                  }
                  else if (Heater_set_High <=7){
                  Heater_set_High = 7;
                  }
                  
                  //to reset the High setpoint after High temperature time or switching it off:
                  
                  if (Heater_High == LOW){
                  Heater_set_High = 17;
                  }
                  
                  

                  I also can change it in the controller by sending a temperature message to the node.

                  When i finished the project i will make a post of this project.

                  1 Reply Last reply
                  0
                  • electrikE Offline
                    electrikE Offline
                    electrik
                    wrote on last edited by
                    #12

                    It is now still activated twice per button press, as this code will be executed on both pressing and releasing the button.
                    You could check if it is high so you can change your setpoint by 0.5 degrees

                    dzjrD 1 Reply Last reply
                    0
                    • electrikE electrik

                      It is now still activated twice per button press, as this code will be executed on both pressing and releasing the button.
                      You could check if it is high so you can change your setpoint by 0.5 degrees

                      dzjrD Offline
                      dzjrD Offline
                      dzjr
                      wrote on last edited by
                      #13

                      @electrik I already dit set it at 0,5 so it is changing 1 degree.

                      I now have made it even 0.05 so i can change it by 0,1 degree.

                      Thanks for all the help!

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


                      15

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 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