#include
#define LED 6
#define Sev_PIN 8
Servo myservo;
int n, i;
void setup() {
// put your setup code here, to run once:
pinMode(Buzzer_PIN, OUTPUT);
myservo.attach(Sev_PIN);
}
void loop() {
for (i = 0; i < 180; i++) {
n = map(i, 0, 180, 400, 1200);
myservo.write(i);
tone(Buzzer_PIN, n);
delay(15);
}
for (i = 180; i > 0; i--) {
n = map(i, 180, 0, 1200, 400);
myservo.write(i);
tone(Buzzer_PIN, n);
delay(15);
}
#include
#define PIN 6
#define NUMPIXELS 2
ColorLED strip = ColorLED(NUMPIXELS, PIN);
int i = 0;
int gap = 1;
void setup() {
strip.begin();
}
void loop() {
// 用for写呼吸灯,控制第一个灯
for (int i = 0; i<=255; i++){
strip.setPixelColor(0, i, 0, 0);
strip.show();
delay(15);
}
for (int i = 255; i>=0; i--){
strip.setPixelColor(0, i, 0, 0);
strip.show();
delay(15);
}
// 用if写呼吸灯,控制第二个灯
i+=gap;
if (i >= 255 || i<=0) {
gap = -gap;
}
strip.setPixelColor(1, i, 0, 0); //设置彩灯编号和颜色,颜色为RGB值或十六进制色彩值
strip.show();
delay(1
立即注册