Arduino
#include <Servo.h>
順便一提的,單顆伺服馬達在運作時,所需電流大約是 300mA。如果你需要 2 顆以上的伺服馬達同時運作,就要外接高電流的變壓器來供電,不然就會經常出現抖動的情況。
Attach the Servo variable to a pin.
servo.attach(pin);
servo.attach(pin, min, max);
Writes a value to the servo, controlling the shaft(軸) accordingly. On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement.
servo.write(angle);
example:
#include <Servo.h>
Servo myservo; // 宣告馬達
void setup()
{
myservo.attach(9);
myservo.write(90);
}
void loop() {}
Writes a value in microseconds (us) to the servo, controlling the shaft accordingly. On standard servos a parameter(參數) value of 1000 is fully counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle.
servo.writeMicroseconds(us)
回傳馬達當前的角度
servo.read()
回傳馬達是否 attach 到腳位(布林值),如果有就回傳 true,否則回傳 false
servo.attached()
將馬達從腳位分離
servo.detach()
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing