自制酷炫的新年灯笼
新年了,灯笼是非常有代表性的新年物件。红红火火的灯笼,既有美好的寓意,也是点缀新年的装饰,还有实用的照明功效。作为DIY爱好者,必须自己做一个。
大概思路:使用ws2812b幻彩灯带,配合亚克力板,板上刻上各种祝福语,投射出炫丽效果来;框架采用3D打印;控制板使用esp01s,(配合直插led模块),连接wifi使用BLINKER进行手机远程控制;顶部300减速电机(5转/分)使灯笼旋转;3节5号电池供电。
材料与成本:整体还是比较便宜,esp01s,6元;RGB模块,5元;减速电机、亚克力和3d打印材料都是几块钱。最贵的却是电池,为了坚持长一点的时间,用的比较好的1.5恒压充电电池,二十块左右一颗,几个灯笼电池花了一百多。三颗电池能坚持近二十个小时,几块钱的比较好的一次性碱性电池,时间差不多,但是每天都得换电池。
外壳:
Ws2812b灯带:
亚克力面板:
Esp01s:
减速电机:
Blinker控制:
App配置了几个控制按钮:
亮灯和黑暗环境下:
外壳改进了一点的新版本:
一对灯笼,红红火火!
改进版新年灯笼
附录代码:
#include <Adafruit_NeoPixel.h>
#include <SimpleTimer.h>
volatile int g_ms;
volatile int g_ld;
volatile int g_xh;
volatile boolean g_zs;
Adafruit_NeoPixel rgb_display_2 = Adafruit_NeoPixel(12,2,NEO_GRB NEO_KHZ800);
SimpleTimer timer;
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "xxxxxxxxxxx";
char ssid[] = "xxxxx";
char pswd[] = "xxxxxxxx";
//
uint32_t Wheel(byte WheelPos){
if(WheelPos < 85){
return rgb_display_2.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170){
WheelPos -= 85;
return rgb_display_2.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else{
WheelPos -= 170;
return rgb_display_2.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void rainbow(uint8_t wait){
uint16_t i, j;
for(j=0; j<256; j ){
for(i=0; i<rgb_display_2.numPixels(); i ){
rgb_display_2.setPixelColor(i, Wheel((i j) & 255));
}
rgb_display_2.show();
delay(wait);
}
}
BlinkerRGB RGB1("yanse");
void RGB1_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value) {
g_zs = false;
g_ld = bright_value;
rgb_display_2.setBrightness(bright_value);
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((r_value & 0xffffff) << 16) | ((g_value & 0xffffff) << 8) | b_value);
rgb_display_2.show();
delay(50);
}
}
BlinkerButton Button2("btn-ss");
void Button2_callback(const String & state) {
g_ms = 2;
g_zs = true;
}
BlinkerButton Button3("btn-hx");
void Button3_callback(const String & state) {
g_ms = 3;
g_zs = true;
}
BlinkerButton Button4("btn-ch");
void Button4_callback(const String & state) {
g_ms = 4;
g_zs = true;
}
BlinkerButton Button5("btn-xz");
void Button5_callback(const String & state) {
g_ms = 5;
g_zs = true;
}
BlinkerButton Button6("btn-xh");
void Button6_callback(const String & state) {
g_ms = 6;
g_zs = true;
}
void shanshuo() {
for (int j = 1; j <= 3; j = j (1)) {
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((255 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(100);
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(50);
}
for (int j = 1; j <= 3; j = j (1)) {
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((255 & 0xffffff) << 16) | ((255 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(100);
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(50);
}
for (int j = 1; j <= 3; j = j (1)) {
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((255 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(100);
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(50);
}
for (int j = 1; j <= 3; j = j (1)) {
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((255 & 0xffffff) << 8) | 255);
rgb_display_2.show();
}
delay(100);
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(50);
}
for (int j = 1; j <= 3; j = j (1)) {
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 255);
rgb_display_2.show();
}
delay(100);
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(50);
}
for (int j = 1; j <= 3; j = j (1)) {
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((255 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 255);
rgb_display_2.show();
}
delay(100);
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
delay(50);
}
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((255 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
}
rgb_display_2.setBrightness(g_ld);
rgb_display_2.show();
}
void Simple_timer_1() {
if (g_zs) {
rgb_display_2.setBrightness(g_ld);
rgb_display_2.show();
switch (g_ms) {
case 2:
shanshuo();
break;
case 3:
huxi();
break;
case 4:
rainbow(50);
rgb_display_2.show();
break;
case 5:
xuanzh();
break;
case 6:
g_xh = g_xh 1;
if (g_xh == 5) {
g_xh = 1;
}
switch (g_xh) {
case 1:
xuanzh();
break;
case 2:
huxi();
break;
case 3:
rainbow(20);
rgb_display_2.show();
break;
case 4:
shanshuo();
break;
}
break;
}
}
}
void huxi() {
for (int j = 1; j <= 5; j = j (1)) {
for (int i = 1; i <= 32; i = i (1)) {
rgb_display_2.setBrightness((i * 3));
rgb_display_2.show();
delay(20);
}
delay(100);
for (int i = 32; i >= 1; i = i (-1)) {
rgb_display_2.setBrightness((i * 3));
rgb_display_2.show();
delay(20);
}
}
rgb_display_2.setBrightness(g_ld);
rgb_display_2.show();
}
void xuanzh() {
for (int j = 1; j <= 2; j = j (1)) {
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((255 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 0);
rgb_display_2.show();
delay(40);
}
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((255 & 0xffffff) << 16) | ((255 & 0xffffff) << 8) | 0);
rgb_display_2.show();
delay(40);
}
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((255 & 0xffffff) << 8) | 0);
rgb_display_2.show();
delay(40);
}
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((255 & 0xffffff) << 8) | 255);
rgb_display_2.show();
delay(40);
}
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((0 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 255);
rgb_display_2.show();
delay(40);
}
for (int i = 1; i <= 12; i = i (1)) {
rgb_display_2.setPixelColor((i)-1, ((255 & 0xffffff) << 16) | ((0 & 0xffffff) << 8) | 255);
rgb_display_2.show();
delay(40);
}
}
}
void setup(){
g_ms = 6;
g_ld = 60;
g_xh = 0;
g_zs = true;
rgb_display_2.begin();
Blinker.begin(auth,ssid,pswd);
rainbow(30);
rgb_display_2.show();
RGB1.attach(RGB1_callback);
Button2.attach(Button2_callback);
Button3.attach(Button3_callback);
Button4.attach(Button4_callback);
Button5.attach(Button5_callback);
Button6.attach(Button6_callback);
timer.setInterval(10000L, Simple_timer_1);
}
void loop(){
//1、yanse,颜色与亮度;2、btn-ss,闪烁;3、btn-hx,呼吸;
//4、btn-ch,彩虹;5、btn-xz,旋转;6、btn-xh,循环。
Blinker.run();
timer.run();
}
Blinker界面配置:
{¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨light¨¨background¨{¨img¨´´}}¨dashboard¨|{¨type¨¨col¨¨t0¨¨颜色亮度¨¨clr¨¨#389BEE¨¨bg¨Ë¨cols¨Ï¨rows¨Ï¨key¨¨yanse¨´x´Ê´y´Ê¨speech¨|÷¨lstyle¨É}{ß8¨btn¨¨ico¨¨fad fa-lightbulb-on¨¨mode¨ÊßA¨闪烁¨¨t1¨¨文本2¨ßEËßFËßGËßH¨btn-ss¨´x´Ï´y´ÒßJ|÷ßKÉßC¨#076EEF¨}{ß8ßLßM¨fad fa-heartbeat¨ßOÊßA¨呼吸¨ßQßRßEËßFËßGËßH¨btn-hx¨´x´Ë´y´ÒßJ|÷ßKÉßC¨#EA0909¨}{ß8ßLßM¨fad fa-sun¨ßOÉßA¨彩虹¨ßQßRßEËßFËßGËßH¨btn-ch¨´x´É´y´ÒßJ|÷ßC¨#FBA613¨}{ß8ßLßM¨fad fa-repeat-alt¨ßOÉßA¨循环¨ßQßRßEËßFËßGËßH¨btn-xh¨´x´Ì´y´¤CßJ|÷ßC¨#00A90C¨}{ß8ßLßM¨fad fa-fan¨ßOÉßA¨旋转¨ßQßRßEËßFËßGËßH¨btn-xz¨´x´Í´y´ÒßJ|÷ßC¨#6010E4¨}÷¨actions¨|¦¨cmd¨¦¨switch¨‡¨text¨‡¨on¨¨打开?name¨¨off¨¨关闭?name¨—÷¨triggers¨|{¨source¨ßm¨source_zh¨¨开关状态¨¨state¨|ßoßq÷¨state_zh¨|¨打开¨¨关闭¨÷}÷}