禁止焊接假日萤火虫灯

419.

3.

简介:禁止焊接假日萤火虫灯

关于:自童年的制造商,所有经典症状,机器人建设者和互联网软件CTO / Tech产品经理。

这是一个假期延伸Firefly / Lightning Bug项目。这是一个禁用的arduino控制的LED线,被编程为像红色和绿色萤火虫等闪烁。尽管如此,您可以编程任何一种照明。该项目非常迅速组装 - 通过使用Arduino Nano和螺钉端子屏蔽,只需用螺丝刀连接三根电线。

你可以看到它们而不是重复构建指令其他指导

关于电源的一个注:由于该项目一次仅闪烁一些LED,因此它正在通过Arduino Nano调节器供电,用于从USB手机备用电池供电。如果更改代码或添加更多LED,则应与Arduino分开向其供电。由于这些是5V LED,您可以使用5V电源来为Arduino和LED供电。

与萤火虫项目的一个不同之处在于这些灯的频率有点高。

图片中的股线有150个LED - 三个50个LED股线连接在一起。代码配置为200,但为您提供足够的电量,您可以轻松添加更多。查看另一个可指示的功率注入等信息。

第1步:代码

以下是用于此项目的代码。如前所述,它还显示了如何在不使用每个灯延迟使用延迟的情况下进行动画 - 允许并行动作。

< p >两个颜色闪烁< br > / / / / 9/3/18——12/13/19 Carl F Sutter

#include #ifdef __AVR__ #include #endif

// Neopixel constants #define PIN 6 #define NUMLEDS 200

// App constants // The RGB values for the first color 0-255 #define COLOR1_R 255 #define COLOR1_G 0 #define COLOR1_B 0

// The RGB values for the second color 0-255 #define COLOR2_R 0 #define COLOR2_G 255 #define COLOR2_B 0

// loop control - these are the main constants to control the animation // note that the math is in integers right now, so if the step size is greater than the color values, it wil not work well #define NUM_STEPS_UP 5 // the number of steps to fade the color up #define NUM_STEPS_DOWN 30 // the number of stesp to fade the color down #define LOOP_DELAY 10 // the ms delay for each loop #define BLINK_ODDS 5 // the odds in 1000 that the loop will start each black pixel

// internal constants and vars - no need to change #define STATE_BLACK 0 #define STATE_MOVING_UP_1 1 #define STATE_MOVING_DOWN_1 2 #define STATE_MOVING_UP_2 3 #define STATE_MOVING_DOWN_2 4

uint8_t state[NUMLEDS]; uint8_t color_r[NUMLEDS]; uint8_t color_g[NUMLEDS]; uint8_t color_b[NUMLEDS];

// Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel. Avoid connecting // on a live circuit...if you must, connect GND first.

void setup() { // set all the LEDS to the no blink (black) state for(int i=0; i

randomSeed(analogRead(0));

strip.begin(); strip.show(); // Initialize all pixels to 'off' } // setup

void loop() { for (int i=0; i

case STATE_MOVING_UP_1: color_r[i] = min(COLOR1_R, color_r[i] + (COLOR1_R / NUM_STEPS_UP)); color_g[i] = min(COLOR1_G, color_g[i] + (COLOR1_G / NUM_STEPS_UP)); color_b[i] = min(COLOR1_B, color_b[i] + (COLOR1_B / NUM_STEPS_UP)); strip.setPixelColor(i, color_r[i], color_g[i], color_b[i]); if ((color_r[i] == COLOR1_R) && (color_g[i] == COLOR1_G) && (color_b[i] == COLOR1_B)) { state[i] = STATE_MOVING_DOWN_1; } // maybe someday make the code cleaner and use less memory - OK for now //uint32_t ColorOfThePixel = MyPixels.getPixelColor(12); //uint8_t r = ColorOfThePixel >> 16; //uint8_t g = ColorOfThePixel >> 8; //uint8_t b = ColorOfThePixel; break;

case STATE_MOVING_UP_2: color_r[i] = min(COLOR2_R, color_r[i] + (COLOR2_R / NUM_STEPS_UP)); color_g[i] = min(COLOR2_G, color_g[i] + (COLOR2_G / NUM_STEPS_UP)); color_b[i] = min(COLOR2_B, color_b[i] + (COLOR2_B / NUM_STEPS_UP)); strip.setPixelColor(i, color_r[i], color_g[i], color_b[i]); if ((color_r[i] == COLOR2_R) && (color_g[i] == COLOR2_G) && (color_b[i] == COLOR2_B)) { state[i] = STATE_MOVING_DOWN_2; } break; case STATE_MOVING_DOWN_1: color_r[i] = max(0, color_r[i] - max(1, (COLOR1_R / NUM_STEPS_DOWN))); color_g[i] = max(0, color_g[i] - max(1, (COLOR1_G / NUM_STEPS_DOWN))); color_b[i] = max(0, color_b[i] - max(1, (COLOR1_B / NUM_STEPS_DOWN))); strip.setPixelColor(i, color_r[i], color_g[i], color_b[i]); if ((color_r[i] == 0) && (color_g[i] == 0) && (color_b[i] == 0)) { state[i] = STATE_BLACK; } break; case STATE_MOVING_DOWN_2: color_r[i] = max(0, color_r[i] - max(1, (COLOR2_R / NUM_STEPS_DOWN))); color_g[i] = max(0, color_g[i] - max(1, (COLOR2_G / NUM_STEPS_DOWN))); color_b[i] = max(0, color_b[i] - max(1, (COLOR2_B / NUM_STEPS_DOWN))); strip.setPixelColor(i, color_r[i], color_g[i], color_b[i]); if ((color_r[i] == 0) && (color_g[i] == 0) && (color_b[i] == 0)) { state[i] = STATE_BLACK; } break; } // switch } // led loop strip.show(); delay(LOOP_DELAY); } // loop

让它发光比赛

参加了这一点
让它发光比赛

是第一个分享

    建议书

    • 让它发光比赛

      让它发光比赛
    • 第一次作家比赛

      第一次作家比赛
    • PCB挑战

      PCB挑战

    讨论