|
|
发表于 2014-8-21 21:10:12
|
显示全部楼层
本帖最后由 eddiewwm 于 2014-8-21 22:06 编辑
发源地 发表于 2014-8-21 09:59 
int pin = 8; //0~13
void setup()
先讓電調控制電機轉起來:
int pin = 8; //0~13
int count =0;
int up =1;
void setup()
{
pinMode(pin,OUTPUT);
while (count<500) // 等待電調初始化,可按需要增長或減短
{
digitalWrite (pin, HIGH);
delayMicroseconds(800);
digitalWrite (pin, LOW);
delayMicroseconds(19200);
count++;
}
count = 1000;
}
void loop() //脈寬循環地 從 1ms 遞增至 2ms 後遞減回 1ms,以改變電機轉速
{
digitalWrite (pin, HIGH);
delayMicroseconds(count);
digitalWrite (pin, LOW);
delayMicroseconds(20000-count);
if ( count == 2000 and up ==1)
{
count--;
up=0;
}
else if (count == 1000 and up == 0)
{
count++;
up = 1;
}
else if (up ==1)
{
count++;
}
else if (up == 0)
{
count--;
}
}
|
|