This is an old revision of the document!


servo_control.ino
#include <Servo.h>
 
int ledPin = 11;
int potPin = 0;
 
int brt = 0;
int angle = 0;
Servo myservo;
 
void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  myservo.attach(10);
 
}
 
void loop() {
  // put your main code here, to run repeatedly: 
  brt = map(analogRead(potPin), 0, 1023, 0, 255);
  angle = map(analogRead(potPin), 0, 1023, 0, 180);
 
  brt = constrain(brt, 0, 255);
  angle = constrain(angle, 0, 180);
 
  Serial.print("brt=");
  Serial.println(brt);
  Serial.print("angle=");
  Serial.println(angle);
  analogWrite(ledPin, brt);
  myservo.write(angle);
}
Print/export
Toolbox