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)
    sys_SetTimer(TIMER1, 1000); //set a timer for 1 second
    digitsval--; //digitsval should be a global variable WriteObject(tLeddigits, 0, digitsval); //changes the value of the digits
    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.