Files
esp8266_study/代码案例/6 Arduino基础学习/27 模拟输出 – 3 for循环/Lesson27-1/Lesson27-1.ino
2024-09-27 01:22:07 +08:00

33 lines
726 B
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
27 模拟输出3 - for
太极创客
www.taichi-maker.com
此程序用于太极创客<<零基础入门学用Arduino教程>>
27 模拟输出3 - for
演示如何通过for循环语句实现LED明暗交替(呼吸灯)效果。
2017-04-28
*/
void setup() {
pinMode(9, OUTPUT); //设置9号引脚为输出模式
Serial.begin(9600); //启动串口通讯
}
void loop() {
// LED由暗到明
for (int brightness = 0; brightness <= 255; brightness++){
analogWrite(9, brightness);
Serial.println(brightness);
delay(10);
}
// LED由明到暗
for (int brightness = 255; brightness >=0 ; brightness--){
analogWrite(9, brightness);
Serial.println(brightness);
delay(10);
}
}