Have a guide or tutorial? Post it up!
#4980390
Hey, everyone.
I'm occasionally building props and would like to add some LED effects. I've learned a bit about using Arduino and IDE, but really learning how to code is well outside my ability.
Is there anyone out there that can help me with some simple sketches?
For example, I'd like to build a doodad with 3 LEDs blinking in sequence and also a potentiometer controlled bar graph running off the same board.
Or make cyclotron lights and power cell lights on the same board. Is that even possible? I don't even need it to do sound effects or anything like that.
I know enough to do an LED sequence OR a bar graph, but I don't know how to combine them into the same sketch. Cuz the boards are expensive.
#4980392
You can definitely do this, the secret is not to use delays in your code because they block everything.

What you want is timers, which use the millis function. Or alternatively use a library like TimedAction which handles this for you, basically saying "run this code every X milliseconds". That way your power cell and Cyclotron can run at entirely different intervals.

Here's an example Arduino sketch which uses two strips of RGB Neopixels (addressable LEDs), one for the Cyclotron and one for the Power Cell:
Code: Select all
#include <Adafruit_NeoPixel.h>

#define CYCLOTRON_PIN 7
#define PCELL_PIN 6

// 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)
Adafruit_NeoPixel cyclotron = Adafruit_NeoPixel(4, CYCLOTRON_PIN, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel powercell = Adafruit_NeoPixel(15, PCELL_PIN, NEO_GRB + NEO_KHZ800);

uint16_t cyclotronDelay = 500;
uint16_t currentCyclotron = 3;
unsigned long previousCyclotronMillis=0;

uint16_t powercellDelay = 70;
uint16_t currentPowercell = 0;
unsigned long previousPowercellMillis=0;

uint32_t red = cyclotron.Color(255,0,0);
uint32_t blue = cyclotron.Color(41, 187, 234);


void setup() {
  cyclotron.setBrightness(255); // set brightness
  powercell.setBrightness(255); // set brightness

  cyclotron.begin();
  cyclotron.show(); // Initialize all pixels to 'off'

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

void loop() {
  tickCyclotron();
  tickPowercell();
}


void tickCyclotron() {
  if (
    ((unsigned long)(millis() - previousCyclotronMillis) >= cyclotronDelay)
    || previousCyclotronMillis == 0
    ) {
    previousCyclotronMillis = millis();
    cyclotron.clear();
    cyclotron.setPixelColor(currentCyclotron, red);

    if (currentCyclotron < (cyclotron.numPixels() -1)) {
      currentCyclotron++;
    } else {
      currentCyclotron = 0;
    }
    cyclotron.show();
  }
}

void tickPowercell() {
  if ((unsigned long)(millis() - previousPowercellMillis) >= powercellDelay) {
    previousPowercellMillis = millis();
    powercell.clear();
    for(uint16_t i=0; i<powercell.numPixels(); i++) {
      if (i <= currentPowercell) {
        powercell.setPixelColor(i, blue);
      }
    }
    currentPowercell++;
    if (currentPowercell >= powercell.numPixels()) {
      currentPowercell = 0;
    }
    powercell.show();
  }
}
This uses millis().

You could simplify this significantly by using TimedAction https://github.com/Glumgad/TimedAction

Edit: Here's how that would look:
Code: Select all
#include <Adafruit_NeoPixel.h>
#include "TimedAction.h"

#define CYCLOTRON_PIN 7
#define PCELL_PIN 6

// 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)
Adafruit_NeoPixel cyclotron = Adafruit_NeoPixel(4, CYCLOTRON_PIN, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel powercell = Adafruit_NeoPixel(15, PCELL_PIN, NEO_GRB + NEO_KHZ800);

uint16_t cyclotronDelay = 500;
uint16_t currentCyclotron = 3;

uint16_t powercellDelay = 70;
uint16_t currentPowercell = 0;

uint32_t red = cyclotron.Color(255,0,0);
uint32_t blue = cyclotron.Color(41, 187, 234);

void tickCyclotron() {
    cyclotron.clear();
    cyclotron.setPixelColor(currentCyclotron, red);

    if (currentCyclotron < (cyclotron.numPixels() -1)) {
      currentCyclotron++;
    } else {
      currentCyclotron = 0;
    }
    cyclotron.show();
}

void tickPowercell() {
    powercell.clear();
    for(uint16_t i=0; i<powercell.numPixels(); i++) {
      if (i <= currentPowercell) {
        powercell.setPixelColor(i, blue);
      }
    }
    currentPowercell++;
    if (currentPowercell >= powercell.numPixels()) {
      currentPowercell = 0;
    }
    powercell.show();
}


TimedAction cyclotronTimer = TimedAction(cyclotronDelay, tickCyclotron);
TimedAction powercellTimer = TimedAction(powercellDelay, tickPowercell);


void setup() {
  cyclotron.setBrightness(255); // set brightness
  powercell.setBrightness(255); // set brightness

  cyclotron.begin();
  cyclotron.show(); // Initialize all pixels to 'off'

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

void loop() {
  cyclotronTimer.check();
  powercellTimer.check();
}
SP Productions, Tyrael liked this
#4980437
Oh, man. You make it look so easy! All this stuff melts my brain.
I want to make it more like the '84 style sequence. Where each led comes on just as the previous one is fading out. I'm working on a Spirit proton pack that I've converted into graphic wall art with some LED filament and blinking lights. Right now the cyclotron and power cell are just lit with a cheap color-shifting rope light, but I want just those two things to look a little more 1984. They don't need startup animations or sound or anything.

I'll link a photo, but I'm not sure if I'm doing it right.

https://photos.app.goo.gl/9Ac7aDQUWgL5rrTJ6
#4980447
Corbidorbidoodle wrote: March 24th, 2023, 1:48 pm Oh, man. You make it look so easy! All this stuff melts my brain.
I want to make it more like the '84 style sequence. Where each led comes on just as the previous one is fading out. I'm working on a Spirit proton pack that I've converted into graphic wall art with some LED filament and blinking lights. Right now the cyclotron and power cell are just lit with a cheap color-shifting rope light, but I want just those two things to look a little more 1984. They don't need startup animations or sound or anything.

I'll link a photo, but I'm not sure if I'm doing it right.

https://photos.app.goo.gl/9Ac7aDQUWgL5rrTJ6
I'm sure that can be done, but that's going to be more complex. My own pack has the LED fadeout on the Cyclotron, to make it look more like incandescent bulbs. But it means you can't just keep track of the current Cyclotron number and loop through all four. You also need to track the current brightness of each (0-255) and then gradually reduce this during each loop.

If you use addressable LEDs you're going to make life much easier, it's significantly less wiring.
For the power cell, two of these soldered together would work well:
https://www.adafruit.com/product/1426
(Note: it might be too long to fit in a Spirit Pack, you could go with a flexible led strip instead if that's the case).
For the Cyclotron, any individual Neopixels would work. Each strip only needs a single arduino pin, plus power. So that's 3 wires for each.

If you want to fade standard LEDs, you'll need to use the PWM pins on the Arduino, of which there probably aren't enough (16 pins for the power cell, 4 pins for the Cyclotron). This is why most people just go with the Neopixels (addressable LEDs).

Here's a Cyclotron I did for someone:


This is much cleaner than running individual wires to each LED, there's just 3 chained together.

And here's a power cell, note how I'm controlling 16 LEDs with only 3 wires:
User avatar
By prodestrian
#4980478
Corbidorbidoodle wrote: March 24th, 2023, 11:26 pm Holy crap! I just watched a couple of tutorials on neopixels, and they're amazing. I had no idea.
I can do pretty much everything I want in just a few minutes.
Uh-oh, we've got you hooked now :lol:

Seriously though, they're incredibly versatile. I used them in my pack and wand (including the barrel LEDs), they're great in traps (many people use the small ring LEDs when the doors open), and you can even buy flexible strips of them and have them in your house (running WLED off an ESP32 with Wi-Fi so you can control the colours and animations from your phone).

Keep in mind Neopixel is just Adafruit's brand name, their generic name is WS2812 LEDs. Some models are RGB, others are GRB, so you just have to select this in your code. You can use Adafruit's code with generic WS2812 LEDs even if you didn't buy them from Adafruit. And there's thousands of example animations out there such as the FastLED library, so you don't need to do all the calculations yourself.

If you ever feel like taking on a more advanced project, there's also open source Proton Pack projects which use Arduino and Neopixels:
https://github.com/MikeS11/ProtonPack
https://github.com/CountDeMonet/ArduinoProtonPack
Tyrael liked this

    While waiting impatiently for Frozen Empire to rel[…]

    Make it that pack, sell it for $599. (While I […]

    Yeah, we've been building this thing for ten[…]

    Someone on FB found it. NARDA ELECTROMAGNETIC RADI[…]