No announcement yet.

Userbutton animation

  • Filter
  • Time
  • Show
Clear All
new posts

  • Userbutton animation

    I've read a post along time ago about a user who wanted a *touchable* userimage object, requiring to add additional magic touch events to detect the area of the image. What I am doing actually, unintentionally, does the same as I found out.

    I use a push-to-start button to start the vehicle. I decided to make it digital, and had it working fine with a static image of a push start button on screen using Both for momentary, for start (press and release (I use both, in case cold weather permits longer cranks, holding it until release sends the 2nd event on release, I will post how I did that too, as a learning tool, i guess.)), and stop.

    Initially when I created/modified gif images in photoshop I did 3 sets of 24 images, transparent, one being 24 images of START, 24 of STOP, and 24 of TAKEOVER (thats for the remote start), for animation purposes. However, it did not work like the userimages widget did. I immediately started looking around and found the APP note on it.

    Don't let the title mislead you, no buttons are blocked, but they are merely arranged in blocks.
    Obviously using image 6,7 or 8 etc request didnt work but...

    Reading on Page 17:

    "When writing to a user button to change blocks, the MSB (most significant byte) has a constant value of 0x80 always"

    Actually, I was able to, instead of using image blocks, manipulate them in a way to act just like a userimage object.
    So, to call image 0, you would actually call 0x8000, and image one is 0x8001, etc
    To make things easier when using this method, it was preferable to use DECIMAL instead of HEX in the host (in my case, teensy 3.5). This is easier to work with, specially for ranges.

    here is a sample arduino code needed to activate the first 2 button images (START and STOP) animations. STOP will show when its running, and START will show when it's off.

      if ( !carIgnition ) {
        if ( ptsAnimation < 32768 || ptsAnimation > 32779 ) ptsAnimation = 32767;
        if ( ptsAnimation > 32779 ) ptsAnimation = 32768;
        Screen2.WriteObject(GENIE_OBJ_USERBUTTON, 0, ptsAnimation);
      if ( carIgnition && carRunning ) {
        if ( ptsAnimation < 32780 || ptsAnimation > 32791 ) ptsAnimation = 32779;
        if ( ptsAnimation > 32791 ) ptsAnimation = 32780;
        Screen2.WriteObject(GENIE_OBJ_USERBUTTON, 0, ptsAnimation);
    in HEX, 0x8000 is 32768 in DECIMAL, so thats the value we start with. The code above checks 2 states, if car is running, or not, and sets the range if it's outbound to sync, increment it through the loop (non-blocking) and show the animation by simulating button block switching
    The only reason why I added a carRunning variable, which is also used by other functions in my sketch, is because when the ignition is cranking, it'll show STOP START STOP after pressing start without it, because thats how the car toggles the start sequence. This prevents the toggling of the image until the RPM's stabilize

    In this video I will demonstrate you the animation between the images:
    the "new text document" shows my current GENIE tab data in the arduino IDE, how it handles the push-to-start button sequence completely by millis() and a uint8_t for sequence-shifting a successful start/stop, ability to constantly crank while held down until let go, or just push and release normally for normal start/stop, without interrupting other lcd code (ex. gauges). Also, it blocks all other press attempts until the sequence finishes, so you cant mess up the sequence by pressing it 20 times before it's done

    Hope this helps people looking for a way to press userimages, it's a 2-in-1 feature

    Attached Files
    Last edited by tonton81; 3 March 2017, 11:02 AM.