Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Bar Graph with Neop...
 
Share:
Notifications
Clear all

Bar Graph with Neopixel

2 Posts
1 Users
0 Reactions
725 Views
(@trace)
Estimable Member
Joined: 5 years ago
Posts: 170
Topic starter  

Hi there everyone, hi @Hans.

After the very successfull Power Rangers Project, I got a new one.

Who does remember the "old" bar graph displays for showing battery status or as a level indicator?

This was used for the Ghostbusters Neutrona Wand. And while there are a bunch of LED bars with controllers and programs for that, they are just multiplexed LEDs. And therefore just one or two colors.

What if we use WS2812 instead? So we can have great color effects and a bunch of animation effects and without the need of extra microcontrollers and a bunch of cables. Of course it later must be a custom PCB with 2020 or 1515 sized LEDs, to have them fit.

But again, I don´t know where to start. Here is a great Youtube Video with a standard bar graph which shows some of the effects I would like to have.

https://www.youtube.com/watch?v=DTDk11H-2_M&t=11s

And here is another Video with additional effects (0:28 and 0:33 are great effects):

https://www.youtube.com/watch?v=lStRRh2pRvs

All I have is this very simple animation for two LEDs travelling from outside to the middle and back again. This way it is difficult to do more than just this. But it is made by me, which is progress :D

#include <FastLED.h>

#define PIN 6 
#define NUM_LEDS 20

CRGB leds[NUM_LEDS];

int pos1 = 0;  // Position of the first LED
int pos2 = NUM_LEDS - 1;  // Position of the second LED
unsigned long previousMillis = 0; 

void setup() {
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(2);
}

void loop() {
  backforth();
}

void backforth(){
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 50) {  // Timing for effect speed
      // Clear all LEDs
  FastLED.clear();

  // Color for both LEDs
  leds[pos1] = CRGB::Red;
  leds[pos2] = CRGB::Red;

  // Update positions for movement
  pos1++;
  pos2--;

  // Check for reaching the end and reverse direction
  if (pos1 >= NUM_LEDS) {
    pos1 = 0;
  }
  if (pos2 < 0) {
    pos2 = NUM_LEDS - 1;
  }

  FastLED.show();
    previousMillis = currentMillis;  // Update for next backforth call
  }
}

So my first idea was to use the Knight Rider effect Hans already made. Then I thought about the Bouncing Ball effect and somehow mirror them, so we have a ball bouncing from each end to the middle. But I am totally lost right now.

Any ideas where to start? I thought it would be easier to have some kind of "mirror function", so we can have a desired effect and just mirror it at the middle of the strip (NUM_LED/2 or so) if it is indeed a mirrored effect.
Later I would like to add a speed variable depending on how long a effect button is pressed. And have a color changing effect, also depending on time. And it would be nice to be able to have a backgrond color. But one step after another.


   
ReplyQuote
(@trace)
Estimable Member
Joined: 5 years ago
Posts: 170
Topic starter  

I might have found a starting point for some of the animations. Only problem is, it is for Neopixel Library. I have tried to convert it to FastLed but it won´t work. Maybe because of the way the fading is written. Probably fadeToBlackBy could be used here?!

Neopixel Code:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 6
int brightness = 50;


Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800);


void setup() {

  strip.begin();
  strip.setBrightness(brightness);
  strip.show();
}

void loop() {

  chaser(255, 0, 0, 1, 3, 5, 80);
}


void chaser(int r, int g, int b, int rounds, int width, int fade, int wait) {
  int faktor = 20 / (fade * 2);
  int r2, g2, b2;

  for (int i = 0; i < strip.numPixels() + width + fade; i++) {

    for (int j = 0; j < width; j++) {
      strip.setPixelColor(i - j, r, g, b);

      for (int f = fade; f > 0; f--) {
        r2 = (r / 20) * (f * faktor);
        g2 = (g / 20) * (f * faktor);
        b2 = (b / 20) * (f * faktor);
        strip.setPixelColor((i - width - fade + f), r2, g2, b2);
      }

      strip.setPixelColor(i - width - fade, 0, 0, 0);
    }
    strip.show();
    delay(wait);
  }

  for (int i = strip.numPixels(); i > 0 - width - fade - 2; i--) {
    for (int j = width; j > 0; j--) {
      strip.setPixelColor(i + j, r, g, b);

      for (int f = fade; f > 0; f--) {
        r2 = (r / 20) * (f * faktor);
        g2 = (g / 20) * (f * faktor);
        b2 = (b / 20) * (f * faktor);
        strip.setPixelColor((i + width + fade - f + 1), r2, g2, b2);
      }

      strip.setPixelColor(i + width + fade + 1, 0, 0, 0);
    }
    strip.show();
    delay(wait);
  }
}

 

My attempt of converting the code to fastLED (not working):

#include "FastLED.h"
#define NUM_LEDS 20
#define PIN 6

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(50);
}

void loop() {

  chaser(0, 255, 0, 1, 3, 5, 80);
}



void chaser(int r, int g, int b, int rounds, int width, int fade, int wait) {
  int faktor = 20 / (fade * 2);
  int r2, g2, b2;

  for (int i = 0; i < NUM_LEDS + width + fade; i++) {

    for (int j = 0; j < width; j++) {
      leds[i - j] = CRGB(r, g, b);

      for (int f = fade; f > 0; f--) {
        r2 = (r / 20) * (f * faktor);
        g2 = (g / 20) * (f * faktor);
        b2 = (b / 20) * (f * faktor);
        leds[i - width - fade + f] = CRGB(r2, g2, b2);
      }

      leds[i - width - fade] = CRGB::Black;
    }
    FastLED.show();
    delay(wait);
  }

  for (int i = NUM_LEDS; i > 0 - width - fade - 2; i--) {
    for (int j = width; j > 0; j--) {
      leds[i + j] = CRGB(r, g, b);

      for (int f = fade; f > 0; f--) {
        r2 = (r / 20) * (f * faktor);
        g2 = (g / 20) * (f * faktor);
        b2 = (b / 20) * (f * faktor);
        leds[i + width + fade - f + 1] = CRGB(r2, g2, b2);
      }

      leds[i + width + fade + 1] = CRGB::Black;
    }
    FastLED.show();
    delay(wait);
  }
}

   
ReplyQuote
Share: