作者: Don Johanneck
[Kitronik][Simply Servos]板(圖 1)解決了在項目中使用多個伺服機構時如何提供充足的 3 V - 12 V 電源軌的問題。內置的 3 V 電源穩壓功能和排針可用于快速添加 [Raspberry Pi][Pico] 以操作伺服機構。但是,如果其他的設備采用三線式引線,且需要 5 V 電源,而且可能需要很大的電流時,該怎么辦呢?比如 [Adafruit]的 [NeoPixel LED 燈條]!
圖 1:Kitronik Simply 伺服機構板。(圖片來源:Kitronik)
最近,我有個想法,用我的遙控飛機制作一架夜間飛行器。我可以在其中安裝任何微控制器,然后想辦法把 NeoPixel 燈條與電源連接,但是,如果使用[伺服引線]能快速完成而且易于維修,將是什么樣的結果呢?Simply 伺服機構板不僅僅適用于伺服機構。選擇該平臺簡化了項目,并最大限度地減少了對定制接線和大量連接器的需求。
本文結尾給出了相關的博客和有趣的視頻鏈接,幫助您詳細了解飛行平臺以及如何改裝遙控飛機。我們使用 [Arduino IDE] 對 Pico 進行編程,以便根據遙控發射器的輸入運行 NeoPixels。我計劃在飛機機身兩側使用“發光”功能,隨著油門的加大,追逐速度也會加快。隨著夜幕降臨,Neopixels 會因亮度過高而使眼睛不舒服。一個輔助通道可用于調暗 LED。最后,當飛機在黑暗中著陸時,有著陸燈將非常方便。與其增加另一個通道,不如在油門達到或低于著陸速度時將底部 NeoPixels 變為亮白色。我使用的是基本編程,但仍有改進空間或者仍能夠探索其他功能。
復制Arduino IDE Code:
//Rx throttle as LED speed control. Rx Aux 2 as dimmer. Channels 1 and 2 as inputs on Simply Servos.
//Remaining servo ports on board (channels 3-8, pins 4-9) used as NeoPixel outputs.
#include < neopixelconnect.h >
//Number of NeoPixels in each string
#define FIN_LEN 34 //Number of NeoPixels on each fin
#define BOT_LEN 28 //Number of NeoPixels on each bottom skid
#define AUX_LEN 61 //Number of NeoPixels on each auxiliary location
#define THRESH 60 //Landing versus flight throttle threshold
//Rx channel Pico GPIO inputs
#define THROT 2
#define AUX2 3
// Create an instance of NeoPixelConnect and initialize it for each strand of NeoPixels
// (pin, number of pixels in string, programmable IO location (0 or 1), programmable IO state machine usage (0-3))
NeoPixelConnect R_Aux(4, AUX_LEN, pio0, 0);
NeoPixelConnect L_Aux(5, AUX_LEN, pio1, 0);
NeoPixelConnect R_Bot(6, BOT_LEN, pio0, 1);
NeoPixelConnect L_Bot(7, BOT_LEN, pio1, 1);
NeoPixelConnect R_Fin(8, FIN_LEN, pio0, 2);
NeoPixelConnect L_Fin(9, FIN_LEN, pio1, 2);
uint8_t AuxSingLED; //Single LED variable on auxiliary string
//Function - Get intensity level from Rx Aux2 output
uint8_t get_pixel_intensity() {
return map(pulseIn(AUX2, HIGH), 900, 2200, 0, 255);
}
//Function - Get speed level from Rx Throttle output
uint8_t get_pixel_speed() {
return map(pulseIn(THROT, HIGH), 990, 1902, 100, 0);
}
void setup() {
pinMode(THROT, INPUT); //Set Pico GPIO pin 2 as input
pinMode(AUX2, INPUT); //Set Pico GPIO pin 3 as input
}
void loop() {
uint8_t LEDInten = get_pixel_intensity(); //Get NeoPixel intensity value
uint8_t LEDSpeed = get_pixel_speed(); //Get NeoPixel speed value
if (LEDSpeed < 10) LEDSpeed = 0; //Dampen lower speed limit
if (LEDSpeed < THRESH) { //Throttle high color
R_Bot.neoPixelFill(LEDInten, 0, 0, true); //Fill string with red
L_Bot.neoPixelFill(LEDInten, 0, 0, true); //Fill string with red
} else { //Throttle low color
R_Bot.neoPixelFill(LEDInten, LEDInten, LEDInten, true); //Fill string with white
L_Bot.neoPixelFill(LEDInten, LEDInten, LEDInten, true); //Fill string with white
}
R_Fin.neoPixelFill(0, LEDInten, 0, true); //Fill string with green
L_Fin.neoPixelFill(0, LEDInten, 0, true); //Fill string with green
R_Aux.neoPixelFill(0, 0, LEDInten, false); //Fill string with blue
R_Aux.neoPixelSetValue(AuxSingLED, LEDInten, 0, 0, false); //Set a NeoPixel to red
R_Aux.neoPixelSetValue(AuxSingLED - 1, LEDInten / 10, 0, 0, false); //Set trailing NeoPixel to dimmed red
R_Aux.neoPixelSetValue(AuxSingLED + 1, LEDInten / 10, 0, 0, true); //Set leading NeoPixel to dimmed red
L_Aux.neoPixelFill(0, 0, LEDInten, false); //Fill string with blue
L_Aux.neoPixelSetValue(AuxSingLED, LEDInten, 0, 0, false); //Set a NeoPixel to red
L_Aux.neoPixelSetValue(AuxSingLED - 1, LEDInten / 10, 0, 0, false); //Set trailing NeoPixel to dimmed red
L_Aux.neoPixelSetValue(AuxSingLED + 1, LEDInten / 10, 0, 0, true); //Set leading NeoPixel to dimmed red
AuxSingLED = AuxSingLED + 3; //Marquis - move R_Aux and L_Aux red LEDs along NeoPixel string 3 pixels at a time.
if (AuxSingLED >= AUX_LEN) AuxSingLED = 0; //If at end of string, return to start.
delay(LEDSpeed); //Set how long to delay code execution cycle depending upon throttle level.
}
Arduino IDE Code END:
< /neopixelconnect.h >
清單 1:用于控制 NeoPixel 燈條的 Arduino IDE 代碼。
消除任何延遲功能都將有益于整個程序,通過操作油門的輸入值或輸入值映射,LED 可以更快地運行。您可根據需要,靈活地選擇其余燈條的圖案或顏色。請記住,飛行員需要依靠可識別的燈光圖案來確定飛機的方位和航向。夜間飛行既有趣又有挑戰性。在傍晚時分練習夜間飛行,仍能同時看到飛機和 LED 燈。
審核編輯 黃宇# NeoPixel
-
微控制器
+關注
關注
48文章
7646瀏覽量
152074 -
led
+關注
關注
242文章
23347瀏覽量
663061 -
開發板
+關注
關注
25文章
5121瀏覽量
98155 -
伺服機構
+關注
關注
0文章
7瀏覽量
7181
發布評論請先 登錄
相關推薦
評論