Square wave function programming on Arduino Due

at the moment i have a function in my code which creates the "red curve" aka setpoint in the graph above. It takes a "setpoint" variable then ramps up to 3.0 Votls, then ramps down to 0.0 Volts with 0.02 Volt steps.

Please have a look at the code:

double setpoint_value_Ramp_Hold_Dump()
            {
              static unsigned long start_millis = 0;
              unsigned long current_millis;
              const unsigned long hold = 1;
              current_millis = millis();
                if (current_millis - start_millis >= hold)
                  {
                    start_millis += hold;
                      if(RampingUp)
                       {
                        setpoint += 0.02;
                        if (setpoint > 3.0)
                          {
                           setpoint = 3.0;
                           RampingUp = false;
                          }
                       }
                        else  // not RampingUp
                         {
                          setpoint -= 0.02;
                           if(setpoint < 0.0)
                            {
                             setpoint = 0.0;
                             RampingUp = true;
                            }
                         }
                   }
               }

There are no timers or counters employed as I understand. I also thought that Timers might be the right way to do it. But before starting to twiggle the Timers, maybe it might be possible to create the similar voltage profile by modifying the above mentioned function of my program. In order to change the "red curve " in graph look like the "violet " one.