自制酷炫的新年燈籠
新年了,燈籠是非常有代表性的新年物件。紅紅火火的燈籠,既有美好的寓意,也是點綴新年的裝飾,還有實用的照明功效。作為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¨|¨打開¨¨關閉¨÷}÷}
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!