Yes, but will you be using that same button to then turn it off too?
To use the same button to turn it on/off, you need a latch.
Example pseudo code:
boolean latch = LOW; // declaired at top of code
// inside the loop() or a function
if(digitalRead(2) == HIGH)
// you will need another variable to block this IF statement if the button is held down ie. Prev_state.
// Also debouncing may be needed, but you have an example code under Examples with the Arduino software
{
latch = ! latch;
}
To do it with two different buttons.
if(digitalRead(2) == HIGH)
{
latch = true; // digital/analogWrite( motor pin, set speed)
}
else if(digitalRead(3) == HIGH)
{
latch = false; // digital/analogWrite( motor pin, 0 or LOW)
}
You need to add boolean latch = false; at the top with the rest of your pins. Another thing, if the motor is to stay on forever when the button is pressed, then why have an else statement that makes it turn off?
To answer your problem, you need another if statement that looks to see if latch is true, then if it is, motor goes on.