效用:控制伺服馬達由20到160度往復旋轉,伺服馬達順時鐘轉到底亮綠燈;伺服馬達逆時鐘轉到底亮紅燈。
應用:汽車擋風玻璃上的雨刷。
電路接法:
程式碼:
#include <Servo.h>
int _ABVAR_1_variablename = 0 ;
Servo servo_pin_3;
void setup()
{
pinMode( 5 , OUTPUT);
pinMode( 6 , OUTPUT);
servo_pin_3.attach(3);
digitalWrite(5 , HIGH);
digitalWrite(6 , HIGH);
}
void loop()
{
for(_ABVAR_1_variablename = 20;
20<=160?_ABVAR_1_variablename <= 160:_ABVAR_1_variablename >= 160;
20<=160?_ABVAR_1_variablename = _ABVAR_1_variablename + 1:_ABVAR_1_variablename = _ABVAR_1_variablename - 1)
{
servo_pin_3.write( _ABVAR_1_variablename );
delay( 10 );
}
digitalWrite(6 , LOW);
delay( 1000 );
digitalWrite(6 , HIGH);
for(_ABVAR_1_variablename = 160;
160<=20?_ABVAR_1_variablename <= 20:_ABVAR_1_variablename >= 20;
160<=20?_ABVAR_1_variablename = _ABVAR_1_variablename + 1:_ABVAR_1_variablename = _ABVAR_1_variablename - 1)
{
servo_pin_3.write( _ABVAR_1_variablename );
delay( 10 );
}
digitalWrite(5 , LOW);
delay( 1000 );
digitalWrite(5 , HIGH);
}
沒有留言:
張貼留言