Announcement

Collapse
No announcement yet.

Incrementing variables

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

  • Incrementing variables

    Here is a block of code I'm working with
    Code:
          <if fire_on="logic" minimum_delta_vote_time="150" id="CountUSB">
            <boolean_operation type="and">
              <parameter1>
                <boolean_operation type="greater than">
                  <parameter1>
                    <variable do="get" name="usbstatus"></variable>
                  </parameter1>
                  <parameter2>
                    <number>5</number>
                  </parameter2>
                </boolean_operation>
              </parameter1>
              <parameter2>
                <boolean_operation type="less than or equal to">
                  <parameter1>
                    <variable do="get" name="usbtime"></variable>
                  </parameter1>
                  <parameter2>
                    <number>4</number>
                  </parameter2>
                </boolean_operation>
              </parameter2>
            </boolean_operation>
            <then>
              <do function="Change Variable" functionTargetID="usbtime" vote_opinion="+1" vote_priority="Low"></do>
            </then>
          </if>
    Basically what I'm doing here is trying to buy myself a half second or so before I flip an output back off. However, this code takes 'usbtime' from 0 to 1, then it never goes any higher. I'm not sure if it's only entering the <then> once, or if vote_opinion=+1 is not working properly. I'm not changing 'usbstatus' while I'm testing this block. Any ideas?

  • #2
    OK just did some more testing and found out <do function="Change Variable" functionTargetID="usbtime" vote_opinion="+1" vote_priority="Low"></do> sets the value to 1 regardless of its previous value. Is there any way to add a number to a variable?

    Comment


    • #3
      Ok so found a way to do it. Hopefully this will help some other people. This same idea can be used with steering wheel controls to create different actions if you hold down the buttons. Also it seems to me like since the COM update the MDX is much more accurate with the timer and delta_vote times. Before they seemed random, now they work as they should.

      Now I have it set up so if you hold 'next track' for longer then one second it starts to send fast forwards every half second after that. If you hold next track for less then a second and let go it advances to the next track.

      This timer in my code below allows me to use the fusion brain to trigger a relay for about a second then turn it back off. RR calls a function that turns on a digital output and sets usbstatus to 10 (high) and usbcount to 0. The relay is used to interrupt the +5V wire on the USB cable leading to my hub up front. This solves all pesky problems with my hub and touchscreen on resuming from hibernate (which the fusion brain always comes out of perfectly )

      Code:
            <if fire_on="logic" minimum_delta_vote_time="150" id="CountUSB">
              <boolean_operation type="and">
                <parameter1>
                  <boolean_operation type="greater than">
                    <parameter1>
                      <variable do="get" name="usbstatus"></variable>
                    </parameter1>
                    <parameter2>
                      <number>5</number>
                    </parameter2>
                  </boolean_operation>
                </parameter1>
                <parameter2>
                  <boolean_operation type="less than or equal to">
                    <parameter1>
                      <variable do="set" name="usbtime">
                          <operation type="add">
                            <parameter1>
                              <variable do="get" name="usbtime"></variable>
                            </parameter1>
                            <parameter2>
                              <number>1</number>
                            </parameter2>
                          </operation>
                      </variable>
                    </parameter1>
                    <parameter2>
                      <number>10</number>
                    </parameter2>
                  </boolean_operation>
                </parameter2>
              </boolean_operation>
            </if>
            <if fire_on="logic" minimum_delta_vote_time="100" id="ResetUSB">
              <boolean_operation type="and">
                <parameter1>
                  <boolean_operation type="greater than">
                    <parameter1>
                      <variable do="get" name="usbstatus"></variable>
                    </parameter1>
                    <parameter2>
                      <number>5</number>
                    </parameter2>
                  </boolean_operation>
                </parameter1>
                <parameter2>
                  <boolean_operation type="greater than">
                    <parameter1>
                      <variable do="get" name="usbtime"></variable>
                    </parameter1>
                    <parameter2>
                      <number>10</number>
                    </parameter2>
                  </boolean_operation>
                </parameter2>
              </boolean_operation>
              <then>
                <do function="Change Variable" functionTargetID="usbstatus" vote_opinion="0" vote_priority="Low"></do>
                <do function="Change Variable" functionTargetID="usbtime" vote_opinion="0" vote_priority="Low"></do>
                <do function="Trigger Output" functionTargetID="Digital Output 0" vote_opinion="Off" vote_priority="Low"></do>
              </then>
            </if>

      Comment


      • #4
        Originally posted by JiC View Post
        OK just did some more testing and found out <do function="Change Variable" functionTargetID="usbtime" vote_opinion="+1" vote_priority="Low"></do> sets the value to 1 regardless of its previous value. Is there any way to add a number to a variable?
        Yup, try:

        vote_opinion="d+1"

        (That will add 1 to whatever the value is)

        Comment


        • #5
          Thanks alejoal. I haven't tried it yet but the way you describe is much cleaner

          Comment


          • #6
            Yes + and - are the signs

            d is add the difference to what it is. Without the d it is make it so.

            So "d1" is add 1, "+1" is make it equal to 1, "d-4" is subtract 4, and so on.
            Fusion Brain Version 6 Released!
            1.9in x 2.9in -- 47mm x 73mm
            30 Digital Outputs -- Directly drive a relay
            15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
            Buy now in the MP3Car.com Store

            Comment

            Working...
            X