#include <Servo.h> //載入函式庫
// 定義伺服馬達橘線接到哪一個PIN腳
#define sg90PIN 9
// 共陽極全彩LED燈模組的V接5V R接pin10 G接pin11 B接pin12
// 定義RGB引腳
#define RED_PIN 10
#define GREEN_PIN 11
#define BLUE_PIN 12
Servo myservo; // 建立SERVO物件
//sg90
//橘 訊號線 D9
//紅 電源 5V
//棕 接地 GND
void setup() {
myservo.attach( sg90PIN);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
myservo.write(45); //旋轉到45度
analogWrite(RED_PIN, 255 - 45); // 共陽極
analogWrite(GREEN_PIN, 255 -45);
analogWrite(BLUE_PIN, 255 -45);
delay(1000);
myservo.write(90); //旋轉到90度 中心點
analogWrite(RED_PIN, 255); // 共陽極
analogWrite(GREEN_PIN, 255);
analogWrite(BLUE_PIN, 0);
delay(1000);
myservo.write(135); //旋轉到135度
analogWrite(RED_PIN, 255); // 共陽極
analogWrite(GREEN_PIN, 0);
analogWrite(BLUE_PIN, 255);
delay(1000);
myservo.write(90);
analogWrite(RED_PIN, 255); // 共陽極
analogWrite(GREEN_PIN, 255);
analogWrite(BLUE_PIN, 0);
delay(1000);
}
留言
張貼留言