器件实验:舵机

Arduino例程,环境: Arduino学习平台搭建配置方式(一)

Micro Servo 9g舵机 SG90

#include <Servo.h>
int potPin = A0;
int motorPin = 12;
int val;
Servo myServo;

void setup() {
  // put your setup code here, to run once:

  myServo.attach(motorPin);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  val = analogRead(potPin);
  val = map(val, 0, 1023, 180, 0);
  myServo.write(val);
  Serial.println(val);
  delay(20);
}