Blink with out delay

Okay so I am running a motor that will need to increase speed after 20 seconds then stop after 20 seconds which is normaly fine to use a deley however it must be able to stop when another button is pushed which cant happen durring a delay. bellow is my code so far but i need help adding in the new code so the motor can increase speed then stop with out using a delay. please help me!

int motorPin = 3;
const int switchPin = 2;
int switchState = 0;
const int switchPin2 = 8;
void setup()
{
pinMode(motorPin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(switchPin2, INPUT);
}

void loop()
{
switchState = digitalRead(switchPin);
if (switchState == HIGH) {
analogWrite(motorPin, 250);
}
switchState = digitalRead(switchPin2);
if (switchState == HIGH) {
analogWrite(motorPin, 0);

}
}

Thank you.

Have you read the blink without delay example? Did you understand it? Can you answer these questions:
How does the example determine what time it is?
How does the example determine when something of interest happened?
How does the example determine is sufficient time has elapsed to require something else to happen?
How does the example make that something else happen?
What else happens at the same time?

Yes i read over it and watched the video that goes with it but I found my self getting lost at parts, I know that it takes the last time the LED was last active then counts from there till the next action I think. As someone reasonably new to Arduino I do find it a hard concept to get my head around.

I do find it a hard concept to get my head around.

It's a very simple concept, really. Something happened (the led was turned on or off). Some time later, something else should happen (the led should be turned off if it's on or should be turned on if it's on). Is it time to make that change?

You have a very similar need. You have a motor that is not at full speed. At various times, you need to increase the speed. At some time, the motor is up to speed. At some time, the motor has been up to speed long enough.

Instead of trying to do the whole job at once. modify the code to do nothing more that declare some variables that will contain the times and speeds. Show what you come up with, and we'll either say yes, that's good, or spin you around, and send you off in a new direction (after explaining why).

Then, you can work on the next step.

to better understand Blink WIthout Delay - have a look at this explanation;
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

This is what i have so far, however I dont know how to tell the program that the motor is running
int motorPin = 3;
const int switchPin = 2;
int switchState = 0;
const int switchPin2 = 8;
int nextTime1 = 5000;
long int goTime;
void setup()
{
pinMode(motorPin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(switchPin2, INPUT);
goTime = millis();
}

void loop()

{
switchState = digitalRead(switchPin);
if (switchState == HIGH) {
analogWrite(motorPin, 120);
}
switchState = digitalRead(switchPin2);
if (switchState == HIGH) {
analogWrite(motorPin, 0);

}
if(millis() >= goTime) functionGo();
}

void functionGo(){
if(motorPin == HIGH) {
analogWrite(motorPin, 250);
}

}

  if(millis() >= goTime) functionGo();There is a fundamental problem right here. goTime is set to millis() in setup() and is never changed. Therefore at any time after goTime is set millis() will always be greater or equal to goTime.

his is what i have so far, however I dont know how to tell the program that the motor is running

You may be able to assume that some time after turning the motor on, it will be turning.
Or you could provide a feedback mechanism

So if i add a number in the function it should work?

if(millis(1000) >= goTime) functionGo();

So if i add a number in the function it should work?

Not like that, no - millis takes no parameters.
You need to update "goTime"

at witch point do i set the time parameters for goTime

The simplest way is to look at the way blink without delay does it, even if it isn't quite correct
Each time through loop(), read millis() into a variable.unsigned long currentMillis = millis();
Reference your calculations to the time now, and the time you last did your action. if(currentMillis - previousMillis > interval) {

peter393:
Yes i read over it and watched the video that goes with it but I found my self getting lost at parts, I know that it takes the last time the LED was last active then counts from there till the next action I think. As someone reasonably new to Arduino I do find it a hard concept to get my head around.

you are still not getting the Blink WIthout Delay properly.
stop what you are trying to do - guessing how millis() works and trying to stumble through hoping to get the right code.

take your time to read through this link i gave you.

retronet_RIMBA1ZO:
to better understand Blink WIthout Delay - have a look at this explanation;
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

you can ask to explain what you don't get from that.
once you get that - you will be using millis() by yourself.
(maybe still tripping over it now and then - but you'll get the hang of it eventually)