可以看到开发板上在GPIO10上挂载了一个LED灯,可以利用它实现入门点灯程序
效果是LED每间隔15毫秒闪烁一下(见视频), 代码如下(来自DFROBOT文档)
/*
* LED breathing light sample
*/
const int ledPin = 10; // Actually output pin after PWM generation
//Set PWM parameter
const int freq = 5000;//PWM frequency
const int ledChannel = 0;//GPIO for signal generation
const int resolution = 8;//8-bit resolution
void setup(){
//PWM parameter setting
ledcSetup(ledChannel, freq, resolution);
//Attach the signal generation channel to the output channel
ledcAttachPin(ledPin, ledChannel);
}
void loop(){
//Start to brighten
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
//Start to dim
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
}
效果是有规律地变暗/变亮(见视频), 代码如下(同样来自DFROBOT文档)
/*
* LED呼吸灯示例
*/
const int ledPin = 10; // PWM生成后实际输出引脚
//设置PWM参数
const int freq = 5000;//PWM频率
const int ledChannel = 0;//信号生成GPIO
const int resolution = 8;//8位分辨率
void setup(){
//PWM参数设置
ledcSetup(ledChannel, freq, resolution);
//将生成信号通道绑定到输出通道上
ledcAttachPin(ledPin, ledChannel);
}
void loop(){
//逐渐变亮
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(3);
}
//逐渐变暗
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(3);
}
}
在安装Arduino库的时候,如果遇到不可跨越的屏障,可以尝试通过代理访问
具体设置如图
将ip与端口设置为代理设置
另外可以参考Arduino IDE 离线添加开发板教程,手动下载库包。
全部0条评论
快来发表一下你的评论吧 !