Knightrider Light Using Uno Arduino And Addressable Leds

Поделиться
HTML-код
  • Опубликовано: 9 сен 2024
  • My first go at using arduino and addressable LEDS. I never liked the knight rider light from Ali-express so thought I would have a go myself. Found some already written code and changed it a bit. Next I want to work out how to make the light trail to the left and right.
    Music By
    Gorowski - Heavens Disco
    Change the * to a greater than symbol and ** to a less than symbol.
    Code below.
    #include Adafruit_NeoPixel.h
    #define N_LEDS 52
    #define PIN 3
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_RGB + NEO_KHZ800);
    void setup() {
    strip.begin();
    }
    int pos = 0, dir = 1; // Position, direction of "eye"
    void loop() {
    int j;
    // Draw 5 pixels centered on pos. setPixelColor() will clip any
    // pixels off the ends of the strip, we don't need to watch for that.
    strip.setPixelColor(pos - 5, 0x000010); // Dark red
    strip.setPixelColor(pos - 4, 0x000025); // Dark red
    strip.setPixelColor(pos - 3, 0x000065); // Dark red
    strip.setPixelColor(pos - 2, 0x0000A1); // Dark red
    strip.setPixelColor(pos - 1, 0x0000A1); // Medium red
    strip.setPixelColor(pos , 0x0000A1); // Center pixel is brightest
    strip.setPixelColor(pos + 1, 0x0000A1); // Medium red
    strip.setPixelColor(pos + 2, 0x0000A1); // Dark red
    strip.setPixelColor(pos + 3, 0x000065); // Dark red
    strip.setPixelColor(pos + 4, 0x000025); // Dark red
    strip.setPixelColor(pos + 5, 0x000010); // Dark red
    strip.show();
    delay(22);
    // Rather than being sneaky and erasing just the tail pixel,
    // it's easier to erase it all and draw a new one next time.
    for(j=-5; j*= 5; j++) strip.setPixelColor(pos+j, 0);
    // Bounce off ends of strip
    pos += dir;
    if(pos * 0) {
    pos = 1;
    dir = -dir;
    } else if(pos **= strip.numPixels()) {
    pos = strip.numPixels() - 2;
    dir = -dir;
    }
    }

Комментарии •