Announcement

Collapse
No announcement yet.

Trying to update Cool Gauge in IF statement - ridiculously slow!

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

  • Eran
    replied
    Hi Vooman,

    Sure. You can email it to me here: john at 4dsystems dot com dot au and I’ll look into your code.

    For the convenience of us both, can you try simplifying your code to a shorter version and include the relevant ones (the parts which you’re having bugs on) only? You may also use the “Zip Project” Tool of Workshop4 IDE under the File Section to ensure that all of your project's relevant files are intact and compressed. This way, your project won’t cost you that much size and will be more suitable for sharing via email.

    Best Regards,

    Leave a comment:


  • VooMan
    replied
    Hi, thanks for the zip file. When I downloaded the files to my Arduino and screen, the gauge didn't work. However, I did use that "map" function to replace all the maths I had going on to translate the Arduino's ADC values into numbers for the gauge. That's a much easier way of doing it!

    The gauge still reacts ridiculously slowly though! It takes about 10 seconds for the needle to move one single increment and I can't see why. It's like there's some sort of weird processing error - like it's stuck doing something else instead of updating the gauge.

    I don't mind posting up my code but I'd prefer not to share the screen publicly yet! Do you have an email address that I can send the files to? The 4DGenie file is over 200MB, so I'll have to share it via WeTransfer.

    Leave a comment:


  • Eran
    replied
    Hi Vooman,

    Tried this code and it seems to be working smoothly on my end with just minor modifications from your attached code.

    *I used a potentiometer in my setup. You may adjust the waitPeriod and notice the delay of the coolGauge’s update.

    I’m not sure if this is what you’re trying to achieve, but if not, then can you please attach a simplified version of your project? Please include only the relevant parts so we can help you more.

    Best Regards,
    Attached Files

    Leave a comment:


  • Trying to update Cool Gauge in IF statement - ridiculously slow!

    Hi. I have a piece of code that reads an analogue pin and updates a cool gauge. At first I just had the code reading the pin and updating the directly. This worked fine, but the movement of the needle was jerky because the screen can't keep up. So next I made an if statement with a non-blocking timer to to control the speed that the needle moves. The needle does move - but ridiculously slowly! About one minor increment every 2 seconds!. And it's always the same even if I completely disable the timer. Pleae can somebody tell me why the heck this is happening and how I can overcome it?

    Here's a snippet of the relevant code. I've cut out a few lines that aren't relevant to this issue. I hope it still makes sense.

    Code:
    void loop()
    {
      static long waitPeriod = 0;  //Set up non-blocking delay to update gauges by this number of milliseconds. (AT ZERO TO DISABLE IT, BUT MAKES NO DIFFERENCE ANYWAY)
      static long prevTime;         // Part of non-blocking delay
      static int BoostTarget;    // Target value for boost gauge (the actual value from the sensor)
      static int BoostCurrent;  // Current boost gauge value
      
    
      genie.DoEvents();   //Genie events are received and queued here.
    
      if(millis() - prevTime >= waitPeriod)  //non-blocking delay
      {
        BoostTarget = analogRead(MAPSensorPin);
        if(BoostCurrent < BoostTarget)
        {
          BoostCurrent++;
          BoostVal = ((3 * BoostCurrent * 10) / 1023);  // ((([3bar - -1bar] * value) / resolution) -1bar) * multiplier
        }
             
       
        if(BoostCurrent > BoostTarget)
        {
          BoostCurrent--;
          BoostVal = ((3 * BoostCurrent * 10) / 1023);
        }
      
          WriteObject(BoostDayColour, BoostVal);
          prevTime = millis();
    }
Working...
X