No announcement yet.

LEDDigit Timer

  • Filter
  • Time
  • Show
Clear All
new posts

  • LEDDigit Timer


    I am building a pump control with a timer function (with LEDdigits as display for the time). I want to adjust the time with a slider and start the timer with a Winbutton. The timer can be stopped by another Winbutton as well.

    Now my Problem:
    I want the LED digits to count down

    My code for start and stop button:
    else if (Event.reportObject.index == 17)         // timer start
    Serial.println("start timer");
    genie.WriteObject(GENIE_OBJ_LED, 3, 1);      //Pump active LED on
    digitalWrite(RelaisOut1, HIGH); //turn pump on
    trackValueTimer = trackValue*1000;        //conversion to milli seconds
    endtimer = millis() + (trackValueTimer);        //save stop time
    while(millis() < endtimer)                          //as long as the timer runs ...
    genie.DoEvents();                                 //wait for stop button
    genie.WriteObject(GENIE_OBJ_LED, 3, 0);         //Pump active LED off
    digitalWrite(RelaisOut1, LOW);            //turn pump off
    else if (Event.reportObject.index == 18)              // timer stop
    Serial.println("stop timer");
    trackValue = 0;
    genie.WriteObject(GENIE_OBJ_LED, 3, 0);                 //Pump active LED off
    digitalWrite(RelaisOut1, LOW);                                      //turn pump off
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, trackValue);          // write zero to led digits
    genie.WriteObject(GENIE_OBJ_SLIDER, 0, trackValue);             //set slider to zero
    I have Workshop 4 PRO and want to try to use the timer from system/media widgets since I couldn't get my arduino code to work (I tried to get another millis() in the while-loop to tick each second).

    Can I somehow adjust the timer in workshop to report a message every second? Or directly reduce the value of the led digits each second?

    Best regards

  • #2
    Hello there,

    If you would like to have a countdown timer in Workshop4 Pro, you can insert Magic Code in the program's main loop to update the Leddigits every second. I would use this code over the timer widget because that is mainly for videos.

    t := sys_GetTimer(TIMER1);
    if( t == 0)[INDENT]sys_SetTimer(TIMER1, 1000); //set a timer for 1 second[/INDENT][INDENT]digitsval--; //digitsval should be a global variable
    WriteObject(tLeddigits, 0, digitsval); //changes the value of the digits[/INDENT]
    Now, all you have to do is add the 'Report Message' handler to the OnChanged event for the Leddigits, that way you can keep track of the time in your Arduino code.

    Click image for larger version  Name:	Screenshot 2020-11-16 144056.png Views:	0 Size:	19.9 KB ID:	74285

    I have also attached the small stopwatch project I used to see how this could work. It uses Workshop4 only but the countdown component should blend pretty well with your existing code. Feel free to take a closer look if you need.



    • #3
      Dear Adem,

      I have found this post similar to my current issue. What I want to achieve is two use two winbutton from 4D display for the stop and pause function. However, my codes which are similar to above don't work properly. Pressing the start button will start the timer and at the same time turn on some GPIO's and pressing the 'pause button will simply retain the current timer value and maintain the status of the gpio until I press again the start button. Is there any way or do you have any idea on how to solve this issue? I am also thinking of using the countdown timer from 4D DISPLAY and then once the leddigit starts then I will read the report from the Leddigit to turn on gpios in the Arduino module as you have suggested. However, the zip file seems not working when I add your code in the magicevent(main loop). Please help to share your thoughts. Thank you.



      • #4

        It seems that you also got an inquiry submitted through our helpdesk. We've already replied to it. Thanks for patiently waiting.

        Please see attached example project. This is the same project that was sent to you through your helpdesk ticket.

        As mentioned, this project demonstrates a simple countdown timer you can try. This requires one MagicEvent and a MagicCode set to Main Loop.

        The MagicEvent is linked to the button's OnChanged Event. This will allow the MagicEvent code to function be triggered during a changed in value for the button from a press or release. The MagicEvent is programmed to set (and/or stop) a timer to a specific starting value. The timer counts down immediately afterwards.

        The MagicCode simply updates the LedDigits with the current timer value every time the main loop of the ViSi Genie program is run.

        I hope this helps

        Best Regards
        Attached Files


        • Toshiyuki
          Toshiyuki commented
          Editing a comment

          This Magic Code will display the decimal point in LED Digits.
          Is there a way to hide the decimal point?

      • #5
        Hi Toshiyuki,

        As far as I know, there are two options if you do not want the decimal point:

        1. In the Object Inspector of your Workshop4 IDE, you can change the Decimal to 0.

        2. Use Custom Digits instead of the standard LED Digits.




        • #6

          Thank you for your reply.

          When Decimal is set to 0, only the part after the decimal point is displayed.
          If the number after the decimal point is 3 digits, it will be displayed normally.
          But don't need less than a second.



          • #7

            I'm sorry.
            My explanation was bad.
            I want to display the value of Timer in Leddgits in minutes.

            // MagicCode0
            var t;

            t := sys_GetTimer(TIMER1);

            WriteObject(tLeddigits, 1, t);


            • #8
              timer start.

              func MagicEvent2(var newval)
              var i ;


              i := img_GetWord(hndl, iLeddigits0, IMAGE_TAG2) ;
              i := i*60000;



              • #9
                Hi Toshiyuki,

                Try to check the attached file as reference.
                I used 2 Magic event on the project, MagicEvent1 is a function triggered sys_SetTimerEvent() that will run if timer reaches zero.

                Thank you.

                Best Regards,
                Attached Files


                • #10

                  Oh, it worked.
                  Thank you very much.


                  • #11
                    Hi Toshiyuki,

                    Good to know it work.
                    Thank you for your update.



                    • #12

                      Please help me again.

                      Is it OK to read the LED DIGITS value below?

                      The value cannot be read.

                      LEDtimer = genie.ReadObject(GENIE_OBJ_LED_DIGITS, 0x01);


                      • #13

                        In the main genieArduino library, no - you cannot read a widget this way.
                        Reading would be done without the "LEDtimer =" at the start and the response would appear in the myGenieEventHandler() function.
                        Please have a look at the demo that comes with the library to see this in action.
                        Lines 81/82 and Lines 146-158

                        However - using the genieArduinoDEV library we have, yes you can do it this way. This new library has a number of improvements and additions.
                        You can also find it in the Arduino IDE library manager too.
                        Here is the section in the readme about reading immediately:
                        It would be this I would imagine:

                        LEDtimer = genie.ReadObject(GENIE_OBJ_LED_DIGITS, 0x01, true);



                        • #14
                          Hi James.

                          Thank you for your reply.

                          I have installed the ViSi-Genie-Arduino-Library-DEV library.

                          However, an error will occur.

                          Did the installation fail?
                          Attached Files


                          • #15

                            Are you including the DEV library at the top of your project, or are you still using the original genieArduino library?

                            #include <genieArduinoDEV.h>