[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/diy/ - Do It Yourself

Search:


View post   

>> No.311079 [View]
File: 71 KB, 1439x773, Capture.jpg [View same] [iqdb] [saucenao] [google]
311079

This is the code I use on my Arduino Uno.
I pulled it from some testing examples.

#include <Servo.h>

Servo myservo;


void setSpeed(int speed){
// speed is from 0 to 100 where 0 is off and 100 is maximum speed
//the following maps speed values of 0-100 to angles from 0-180,
// some speed controllers may need different values, see the ESC instructions
int angle = map(speed, 0, 100, 0, 180);
myservo.write(angle);
}

void setup()
{
myservo.attach(8);
}


void loop()
{
int speed;

// sweep up from 0 to to maximum speed in 20 seconds
for(speed = 0; speed <= 100; speed += 5) {
setSpeed(speed);
delay(1000);
}
// sweep back down to 0 speed.
for(speed = 95; speed > 0; speed -= 5) {
setSpeed(speed);
delay(1000);
}
setSpeed(0);
delay(5000); // stop the motor for 5 seconds
}

Navigation
View posts[+24][+48][+96]