Nano + PIR + sequence speed DC motor


I used the code (bellow) on my nano to detect presence and turn on a dc motor.

I would like to make it launch “speed sequence” instead.

Something like

0-1000ms = 0 to max speed (exponential)
1000ms-1200ms = 0 speed
1200ms-2200ms = 0 to max speed (exponential)
2200ms-2400ms = 0 speed
2400ms-6000ms = max speed

Something like that, a choregraphy for DC motor.

I m aware it is a big change to that code bellow, hope someone can help

// this constant won’t change:
const int PIRPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to

// Variables will change:
bool PIRoutput = false; // counter for the number of button presses
int PIRstate = 0; // current state of the button
int LastPIRstate = 0; // previous state of the button

void setup() {
// initialize the pin 2 as a input:
pinMode(PIRPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);

void loop() {
// read the input pin:
PIRstate = digitalRead(PIRPin);

// compare the buttonState to its previous state
if (PIRstate != LastPIRstate) {
// if the state has changed, increment the counter
if (PIRstate == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
PIRoutput = true;

else {
// if the current state is LOW then the button
// wend from on to off:
// Serial.println(“off”);
PIRoutput = false;
// Delay a little bit to avoid bouncing
// save the current state as the last state,
//for next time through the loop
LastPIRstate = PIRstate;

// turns on the LED every time PIR sensor detects motion
if (PIRoutput == true) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);