P-Loop for Flywheel?

Does anyone have an example of a proportional-loop for flywheel rpm? I have used a p-loop for my drive base, but I’m not sure how to make one for my 2-motor flywheel. For reference, here is my old drive base p-loop function:

void proportionalDrive (vex::directionType type, int targetInches, int power)
    FrontLeft.resetRotation ();
    FrontRight.resetRotation ();

    double encoderAverage = (FrontLeft.rotation (vex::rotationUnits::raw) 
                          + FrontLeft.rotation (vex::rotationUnits::raw))/2;
    int targetTicks = (targetInches*225) / M_PI;
    float kP = 0.3;
    while (fabs(encoderAverage) < targetTicks)
        int error = FrontLeft.rotation (vex::rotationUnits::raw) 
                    - FrontRight.rotation (vex::rotationUnits::raw);
        setLeftDrive (type, power - error * kP);
        setRightDrive (type, power + error * kP);
        vex::task::sleep (20);
    stopLeftDrive ();
    stopRightDrive ();

So the basic logic behind the P-loop for your flywheel will be as follows:

You are going to want your flywheel to reach a certain speed of your choosing, then you want it stay at that relative speed for a certain amount of time, rather than fluctuating. So what you COULD do is make an error margin of a few RPM differences. Like lets say an error of 20, 10 higher, 10 lower. What you could do is once you say you want the flywheel to go to your preferred speed, you make an if statement, stating that if it goes past targetValue - 10, then speed up to preferred speed + 5, then the same for the upper margin. I hope this helped, i’m sorry that i did not provide an example.

I’ll be sure to give that a try. My flywheel is extremely jank with the maximum achievable rpm being 60, so my error margin will probably have to be +/- 5.