Announcement

Collapse
No announcement yet.

Can't write to winbutton

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

  • Can't write to winbutton

    I am using a 32DCT-CLB and an arduino. I am having trouble writing value to a winbutton and to contrast after I have powered the screen up. However the screen works fine ie - I can use the winbuttons and change the contrast via slider on another form but i cannot update the value of button. Any ideas??

    void setup()
    {
    Serial.begin(115200);
    gSerial.begin(38400);
    genie.Begin(gSerial);
    genie.AttachEventHandler(myGenieEventHandler);
    CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ);
    Serial.println("MCP2515 Initialized Successfully!");
    CAN0.setMode(MCP_NORMAL);
    pinMode(bz, OUTPUT);
    pinMode(A_IN1, INPUT);
    pinMode(A_IN2, INPUT);
    pinMode(A_IN3, INPUT);
    pinMode(A_IN4, INPUT);
    pinMode(ScreenPW, OUTPUT);
    pinMode(D_OUT0, OUTPUT);
    pinMode(D_OUT0, OUTPUT);
    pinMode(RESETLINE, OUTPUT);
    digitalWrite(ScreenPW, LOW);

    digitalWrite(RESETLINE, HIGH);
    delay(100);
    digitalWrite(RESETLINE, LOW);
    delay(4000);
    acc_check = 1;
    wdt_enable(WDTO_4S);
    // genie.ReadObject(GENIE_OBJ_WINBUTTON, 0);
    }

    void loop()
    {
    wdt_reset();
    genie.DoEvents();
    CANRX();
    if(acc == 1 || ign == 1)
    {
    acc_timeout = (millis() + 15000);
    }
    if((acc == true || ign == true) && acc_check == 0)
    {
    acc_check = 1;
    screenoff = false;
    digitalWrite(ScreenPW,LOW);
    digitalWrite(RESETLINE, HIGH);
    delay(500);
    digitalWrite(RESETLINE, LOW);
    wdt_reset();
    delay(3000);
    wdt_reset();
    delay(2000);
    wdt_reset();
    Serial.println(" write buttons ");
    delay(500);
    genie.WriteObject(GENIE_OBJ_WINBUTTON, 0x00, Drive);
    genie.WriteObject(GENIE_OBJ_WINBUTTON, 0x01, Flash);
    genie.WriteObject(GENIE_OBJ_WINBUTTON, 2, Work);
    //genie.WriteContrast(dimmerVal);

    }
    if((millis() > acc_timeout) && acc_check == 1)
    {
    digitalWrite(ScreenPW, HIGH);
    screenoff = true;
    acc_check = 0;
    }
    if(millis() > 4294967285)
    {
    last_rx = 20;
    last_tx = 20;
    delay(50);
    }

    if(millis() > last_tx)
    {
    if(screenoff == false)
    {
    CANTX();
    }
    last_tx = last_tx + cycle_tx;

    }

    if(millis() > last_sw)
    {
    screenWrite();
    last_sw = last_sw + cycle_sw;
    }
    if(millis() - lts_100 > 3000)
    {
    ol_100 = false;
    }
    if(millis() - lts_240 > 3000)
    {
    ol_240 = false;
    }
    if(millis() - lts_100 > 3000)
    {
    ol_100 = false;
    }
    if(millis() - lts_300 > 3000)
    {
    ol_300 = false;
    }
    if(millis() - lts_400 > 3000)
    {
    ol_400 = false;
    }
    if(millis() - lts_500 > 3000)
    {
    ol_500 = false;
    }

    digitalWrite(D_OUT0,sw24);
    digitalWrite(D_OUT1,sw25);
    Ain1 = analogRead(A_IN1);
    Ain2 = analogRead(A_IN2);
    Ain3 = analogRead(A_IN3);
    Ain4 = analogRead(A_IN4);

    // ScreenUpdate();
    // screenWrite();
    }


  • #2
    Hello,

    I don't think you could do that.

    What I would suggest instead is Putting a Userimage over a winbutton.

    The userimage should resemble the frames of the winbutton.

    The userimage could then be written to siimilar to what you're doing.

    May I know what you're trying to achieve with this?

    Best regards,
    Michael

    Comment


    • #3
      Hi,

      Yes you can do that. It is just writing an ON/OFF to the button if it had changed elsewhere. I did mange to get it working. I called it later on in screenWrite() in exactly the same manner and it worked fine, I can't explain why it doesn't work in my code as above. Any thoughts on this would still be appreciated though.

      Comment


      • #4
        Glad you got it working!

        That's interesting, could you send your code so we can inspect it more thoroughly?
        Michael

        Comment


        • #5
          It is messy as it is a WIP.
          Attached Files

          Comment


          • #6
            Hello ,

            Apologies for my previous comments.

            You could write to a winbutton but the changes won't be obvious unless you add a caption to it.

            First, the button should be configured as momentary no.

            To make the changes more obvious, you can then set a caption for Status when on and Status when off.

            This is optional and the value of the button will still be the same as written to it but the look of the button may not change if this is not done.


            The first code that you sent seems to be writing on the button but it seems to be causing an overflow as the display is resetting. This could be due to recurssion.

            For the second one, this seems to be handled a little better and the display isn't resetting. I think this is because a dedicated function was created for Writing to the buttons and a more elaborate if conditional/ switch case is implemented.

            Please note that I've only been testing the communication between the arduino and the display, I've commented out all other unecessary parts for me.

            I hope this helps.

            Best regards,
            Michael

            Comment


            • #7
              Hi,

              Thanks for the reply and fro trying it.

              My buttons do have captions to indicate the status, that is how I knew it was not updating..

              Could you please elaborate on "The first code that you sent seems to be writing on the button but it seems to be causing an overflow as the display is resetting. This could be due to recurssion." as I don't quite understand what you are saying there.

              As an aside, I often see people being reprimanded on this forum for not showing code properly "use code tags" for example. I looked into how to add code tags when I initially added this but could find no information about it. If this is something that is required usually, it needs to be easier/more obvious how to do it. Any thoughts?

              Thanks
              Cameron

              Comment


              • #8
                Hello Cameron,

                Sorry, I commented out .

                Code:
                acc_check = 1;
                on your first code, that was what's causing the multiple resets.

                Other than that, it seems to work fine.

                Are you sure you've set your buttons to momentary-no when you were trying this for the first time?

                Failing to do so will result in a lack of frames for the buttons, this would show up as red X's when you try to write to them.

                As for using code tags, please see the below photo.

                Click image for larger version

Name:	Wrap Code.png
Views:	1
Size:	21.2 KB
ID:	66202
                I hope this helps,

                Best regards,
                Michael

                Comment


                • #9
                  Yes they are set to be momentary-no.... It works fine elsewhere like I said, but why not here?

                  Comment

                  Working...
                  X