#include <Arduino.h>
int ledRpin = 6;
int ledGpin = 5;
int ledBpin = 3;
void setup() {
Serial.begin(9600);
pinMode(ledRpin, OUTPUT);
pinMode(ledGpin, OUTPUT);
pinMode(ledBpin, OUTPUT);
}
void loop() {
while(1){
breathR();
breathG();
breathB();
}
}
void breathR(){
int brightR = 0;
for(brightR; brightR < 255; brightR+=5){
analogWrite(ledRpin, brightR);
analogWrite(ledGpin, 0);
analogWrite(ledBpin, 0);
Serial.print("红灯亮度为");
Serial.println(brightR);
delay(10);
}
for(brightR; brightR > 0; brightR-=5){
analogWrite(ledRpin, brightR);
analogWrite(ledGpin, 0);
analogWrite(ledBpin, 0);
Serial.print("红灯亮度为");
Serial.println(brightR);
delay(10);
}
}
void breathG(){
int brightG = 0;
for(brightG; brightG < 255; brightG+=5){
analogWrite(ledRpin, 0);
analogWrite(ledGpin, brightG);
analogWrite(ledBpin, 0);
Serial.print("绿灯亮度为");
Serial.println(brightG);
delay(10);
}
for(brightG; brightG > 0; brightG-=5){
analogWrite(ledRpin, 0);
analogWrite(ledGpin, brightG);
analogWrite(ledBpin, 0);
Serial.print("绿灯亮度为");
Serial.println(brightG);
delay(10);
}
}
void breathB(){
int brightB = 0;
for(brightB; brightB < 255; brightB+=5){
analogWrite(ledRpin, 0);
analogWrite(ledGpin, 0);
analogWrite(ledBpin, brightB);
Serial.print("蓝灯亮度为");
Serial.println(brightB);
delay(10);
}
for(brightB; brightB > 0; brightB-=5){
analogWrite(ledRpin, 0);
analogWrite(ledGpin, 0);
analogWrite(ledBpin, brightB);
Serial.print("蓝灯亮度为");
Serial.println(brightB);
delay(10);
}
}