Lesson 10: A servo motor
หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
English
Turn to an angle
- A servo is a motor that turns to an angle from 0° to 180° and stays there.
- It is in robots, model planes and doors that open by themselves.
- Arduino's
Servolibrary does the hard work.#include <Servo.h>loads it.
#include <Servo.h>
Servo arm;
void setup() {
arm.attach(9); // the servo's signal wire is on pin 9
arm.write(0);
delay(1000);
arm.write(180);
}
void loop() {
}
Servo arm;makes a servo object calledarm.arm.write(90);turns it to 90°.- The servo needs about half a second to move.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Attach a servo on pin 9 and turn it to 45°.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Turn the servo on pin 9 with the knob on A0: read A0, use map to change 0–1023 into 0–180, and write the angle. Do it again and again.
คลิก Run เพื่อดูผลลัพธ์ที่นี่