0% found this document useful (0 votes)
2 views

Motor Code

Uploaded by

ARs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Motor Code

Uploaded by

ARs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

int motorPin = 9; //pin the motor is connected to

void setup() //runs once void


{
pinMode(motorPin, OUTPUT); //0 (stopped) and 255 (full speed)
}
void loop() // run over and over again //0 (stopped) and 255 (full speed)
{
motorOnThenOff();
//motorOnThenOffWithSpeed(); // turns the motor On
//motorAcceleration();
}
void motorOnThenOff()
{
int onTime = 2500;
int offTime = 1000;
digitalWrite(motorPin, HIGH);
delay(onTime);
digitalWrite(motorPin, LOW);
delay(offTime);
}

void motorOnThenOffWithSpeed(){
int onSpeed = 200;// a number between
int onTime = 2500;
int offSpeed = 50;// a number between
int offTime = 1000;
analogWrite(motorPin, onSpeed);
delay(onTime); // waits for onTime milliseconds
analogWrite(motorPin, offSpeed);
delay(offtime);
}

void motorAcceleration(){
int delayTime = 50; //time between each speed step
for(int i = 0; i < 256; i++){
analogWrite(motorPin, i);
delay(delayTime);
}
for(int i = 255; i >= 0; i--){
analogWrite(motorPin, i);
delay(delayTime);
}
}

You might also like