Announcement

Collapse
No announcement yet.

If's and then's and remote switches

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • If's and then's and remote switches

    So I have a remote device that serial puts out data depending on one or more switches are pressed. There are 3 switch inputs on this transmitter. One can press #1,2,3 and a bit is set and sent to denote which of the 3 has been pressed but also you can press any combination of the 3 and serially send the bit numbers addition of more than one button (in other words 7 possible switch closures).
    My question is, what is involved to differentiate me pressing the first and say a second button. In other words; no one can exactly press two buttons at exactly the same time so if in say an 'if' statement a single switch is pressed, it might be seen as that single button rather than the eventual second switch's addition to the first switch being pressed.

  • #2
    Perhaps a software debounce. How often is your device transmitting? For a software debounce, check your PORTpins, if one is pressed, pause 100 (ms) and check them again. If the results are the same, GOSUB TakeAction1. If on recheck the button combination changed, PAUSE 100 again and check again. When the readings are the same 2X in a row, GOSUB TakeActionX. If your transmissions are more frequent than 100 ms, you might just track what the buttons are each transmission and wait for 2 or even 5 transmissions that are the same; IF Prev <> Now THEN CheckAgain : ELSEIF Prev = Now THEN TakeAction.
    We can crack this cotton PIC'n thang!

    Comment


    • #3
      Sounds good Mike. I was thinking some debounce or repeat if's but kept second guessing myself.
      The serial out is 9600 baud and it looks like 15 ms wait betweens. If you care to see the .pdf, I've attached.But it's a bit long wind'd
      Attached Files

      Comment


      • #4
        What I would do is starting an accumulator with zero as all of the port bits are clear, merely accumulate the maximum value of the port pins being read after some debounce time, and when the port value read is lesser then the accumulated value, take the accumulated value and send it to the transmitter. Does that make sense?
        Dave Purola,
        N8NTA
        EN82fn

        Comment


        • #5
          I do get that David, the problem is, my transmitter works on 3 input pins that take switches. No micro and thus no programming. The micro is on the receiver to interpret. But that is a sound way to do this if it was doable.

          Comment


          • #6
            It is exactly the same but instead of reading the port pins you would be accumulating the serial data value. Then after some period of time use the highest value.
            Dave Purola,
            N8NTA
            EN82fn

            Comment


            • #7
              OOpps, I forgot the atrtachment....
              Attached Files
              Dave Purola,
              N8NTA
              EN82fn

              Comment


              • #8
                I just found another version where I fixed a math problem.
                Attached Files
                Dave Purola,
                N8NTA
                EN82fn

                Comment

                Working...
                X