if (Model.NotificationsEnabled) { }

使用伺服机构开发板控制 NeoPixel LED

Kitronik Simply Servos 板(图 1)解决了在项目中使用多个伺服机构时如何提供充足的 3 V - 12 V 电源轨的问题。内置的 3 V 电源稳压功能和排针可用于快速添加 Raspberry Pi Pico 以操作伺服机构。但是,如果其他的设备采用三线式引线,且需要 5 V 电源,而且可能需要很大的电流时,该怎么办呢?比如 AdafruitNeoPixel 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 LED 指示灯遥控夜间飞行

博客:如何构建低成本 Combat UAV

关于此作者

Image of Don Johanneck

Don Johanneck 是 DigiKey 的技术内容开发人员,自 2014 年以来一直在该公司工作。他最近刚转岗到现在的职位,负责撰写视频说明和产品内容。Don 通过 DigiKey 奖学金计划获得了北国社区技术学院电子技术和自动化系的应用科学副学士学位。他喜欢无线电控制建模,老式机器修复和修补。

More posts by Don Johanneck
 TechForum

Have questions or comments? Continue the conversation on TechForum, Digi-Key's online community and technical resource.

Visit TechForum
mmmmmmmmmmllimmmmmmmmmmlli