Announcement

Collapse
No announcement yet.

4Dbutton state change from Arduino

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

  • 4Dbutton state change from Arduino

    Can i change the state of a 4Dbutton from Arduino code, like in ViSi-Genie code:
    Code:
    img_SetWord(hndl, i4Dbutton6, IMAGE_INDEX, 1);
    img_Show(hndl, i4Dbutton6);
    ?

  • #2
    The ViSi-Genie parameters
    Code:
    img_SetWord(hndl, i4Dbutton6, IMAGE_INDEX, 0..1..2..3);
    doesn't work in Arduino
    Code:
    genie.WriteObject(GENIE_OBJ_4DBUTTON, 6, 0..1..2..3)
    No documentation, no idea, great...

    Comment


    • #3
      img_SetWord() and img_Show() are 4DGL internal functions. At the Arduino level they are available in the serial environment.

      When using the Genie Environment you have genie.WriteObject(), which is some ways is similar, but is also different, as Genie attempts to control the buttons as buttons, rather than as a series of images.

      So what are you trying to achieve?
      Mark

      Comment


      • #4
        wolfmanus,

        You can change the state of the 4D button by using this Arduino Visi-Genie Code:
        I tested it and it works.
        void loop()
        {

        long waitPeriod = millis();

        genie.DoEvents(); // This calls the library each loop to process the queued responses from the display



        if (millis() >= waitPeriod)
        {
        // Write to CoolGauge0 with the value in the gaugeVal variable
        genie.WriteObject(GENIE_OBJ_4DBUTTON, 0, 1);
        delay(1000);
        genie.WriteObject(GENIE_OBJ_4DBUTTON, 0, 0);
        delay(1000);
        waitPeriod = millis() + 10; // rerun this code to update Cool Gauge and Slider in another 50ms time.
        }
        }

        In 4D Workshop of your Visi-Genie project, change the Momentary Property of the 4DButton to NO so it will toggle to two states.

        Best regards,

        Comment


        • wolfmanus
          wolfmanus commented
          Editing a comment
          Hi Noel, thanks the replay!

          It works, BUT:
          The Arduino "genie.WriteObject(GENIE_OBJ_4DBUTTON, 0, param)" is not same as Visi-Genie "img_SetWord(hndl, i4Dbutton6, IMAGE_INDEX, param)". The two "param" is not equal.

          In the "genie.WriteObject(GENIE_OBJ_4DBUTTON, 0, param)" the "param" have ONLY two values:
          -0 the button is not pressed, dark.
          -1 the button is not pressed, light.

          In the "img_SetWord(hndl, i4Dbutton6, IMAGE_INDEX, param)" the "param" have four values:
          -0 the button is not pressed, dark
          -1 the button pressed, dark
          -2 the button not pressed, light
          -3 the button pressed, light
      Working...
      X