本文來(lái)源電子發(fā)燒友社區(qū),作者:jf_68700789, 帖子地址:https://bbs.elecfans.com/jishu_2291456_1_1.html
點(diǎn)燈(開(kāi)發(fā)板體驗(yàn)視頻,詳見(jiàn)作者原文帖子內(nèi)容)
硬件外觀
可以看到開(kāi)發(fā)板上在GPIO10上掛載了一個(gè)LED燈,可以利用它實(shí)現(xiàn)入門(mén)點(diǎn)燈程序
簡(jiǎn)單點(diǎn)燈
效果是LED每間隔15毫秒閃爍一下(見(jiàn)視頻), 代碼如下(來(lái)自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);
}
}
呼吸燈(PWM)
效果是有規(guī)律地變暗/變亮(見(jiàn)視頻), 代碼如下(同樣來(lái)自DFROBOT文檔)
/*
* LED呼吸燈示例
*/
const int ledPin = 10; // PWM生成后實(shí)際輸出引腳
//設(shè)置PWM參數(shù)
const int freq = 5000;//PWM頻率
const int ledChannel = 0;//信號(hào)生成GPIO
const int resolution = 8;//8位分辨率
void setup(){
//PWM參數(shù)設(shè)置
ledcSetup(ledChannel, freq, resolution);
//將生成信號(hào)通道綁定到輸出通道上
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);
}
}
關(guān)于網(wǎng)絡(luò)的一些坑
在安裝Arduino庫(kù)的時(shí)候,如果遇到不可跨越的屏障,可以嘗試通過(guò)代理訪問(wèn)
具體設(shè)置如圖
將ip與端口設(shè)置為代理設(shè)置
另外可以參考Arduino IDE 離線添加開(kāi)發(fā)板教程,手動(dòng)下載庫(kù)包。
-
ESP32
+關(guān)注
關(guān)注
18文章
971瀏覽量
17412 -
DFRobot
+關(guān)注
關(guān)注
4文章
1158瀏覽量
9587
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論