Neopixel Lightsaber Katana

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel Lightsaber Katana

Post by adafruit_support_bill »

If you disconnect the led strip does the battery charge? The WS2811 chips in the pixels do require current to operate - even when the leds are turned off. This will take away from any battery charging current.

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

I hadn't actually tried that, Ill see if I have some quick disconnects I can solder in between the LEDs and the board to test this when I get home today. Thanks!

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

I desoldered the +/- of the Neopixels from the board and blugged the battery and charge cable back up, and it managed to charge a 4400mah battery in minutes.... so if thats the way it should work, where should I solder the +/- leads for the LEDs if not there? I can see a few different 5V spots on the Pro Trinket board but just wanna make sure im soldering to the right place so that it can charge the battery properly.

Another question: the power switch you can wire up to the backpack board, does that cut all power or while its in the off position does it still charge the battery?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel Lightsaber Katana

Post by adafruit_support_bill »

You can wire them as you had them to the back of the Trinket. The optional on/off switch cuts power to the circuit (and the pixels), but will still charge the battery.

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

So right now the Neopixel strip is just taped to the back of the blade as a test, but.....

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

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel Lightsaber Katana

Post by adafruit_support_bill »

Looking good! Thanks for the video.

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

So now that the programming for the Trinket and Neopixel strip are good, I get to start playing with the audio/ accelerator part of this build. I remember someone posted this Accelerometer ( https://www.adafruit.com/products/163) earlier and im thinking about wiring it as a switch to this: https://www.adafruit.com/products/2210 and then have one of these 1W metal speakers running off it https://www.adafruit.com/products/1890. The catch with all of this is that it will need its own powersource so I would need an additional backpack/battery setup.

I feel like there should be an easier way to do this... like some way to add a sound board to the Pro trinket so that i can use it to trigger sounds and everything runs off the same battery setup....Im totally open to suggestions on this, thanks!

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel Lightsaber Katana

Post by adafruit_support_bill »

im thinking about wiring it as a switch to this...
That accelerometer has analog outputs. It is not going to function well as a switch.
A better option is to run the analog inputs to analog pins on the Pro Trinket. Then have your program read and react to the acceleration forces by triggering sounds on the FX board. You could run it all off the same battery supply.

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

Ahhh ok thats good to know, Ill have to look into how the coding works for reading the accel over teh analog pins will work. As far as powering all of this off the same battery pack, would I just run wire from the 5V/GND pins on the Pro Trinket to the necessary pins on the accel/ sound boards and this would be enough?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel Lightsaber Katana

Post by adafruit_support_bill »

would I just run wire from the 5V/GND pins on the Pro Trinket to the necessary pins on the accel/ sound boards and this would be enough?
Yes, that should do it.

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

NICE! That makes this a lot simpler to wire up, and means I dont need a whole extra power system to keep track of. That being the case, Ive been reading up on teh AudioFX board some more ( the intro and learning section as well as projects for it) and from what Im reading( https://learn.adafruit.com/adafruit-aud ... io-control), the whole curcuit should sounds something like this:

Accel is wired to the analog pins on the side of the Pro Trinket and programmed so that when they hit certain points they trigger the AudioFX board.

AudioFX board is wired from the Rx/Tx to pins 6 and 7 on Trinket and 5v/GND making sure the GND on Trinket is wired to the UG pin on the AudioFX board to put it in serial mode so I can control it with the Trinket.

After that I can use the code from https://github.com/adafruit/USBgamepad/ ... _test2.ino to get a better understanding of how the board interprets the data, but i think it would read something like:
if AccelX is greater than X then PT09.OGG\n over soft serial
if AccelY is greater than Y then PT01.OGG\n over soft serial

Am I reading this right?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel Lightsaber Katana

Post by adafruit_support_bill »

It sounds like you are on the right track there.

The accelerometer outputs will be about mid-scale when not moving.

Code: Select all

//The average zero acceleration values read
//from the accelerometer for each axis:
const int cintZeroXValue = 328;
const int cintZeroYValue = 328;
const int cintZeroZValue = 328;
The readings on a given axis will increase when moving in one direction and decrease when moving in the opposite direction. This code looks at the deviation from that zero point.

Code: Select all

  if( cintMovementThreshold < abs( intAnalogXReading - cintZeroXValue ) )

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

So Ive been working on the code for this and pouring over the details on how the adafruit soundboard library but my brain just isnt making the connection on how I can get the Pro trinket to make the call to the AudioFX board to play the file I need.

I tried setting up the FX board in UART mode and using software serial I cant seem to get it to pass the command to the Audio board to play the sound.

Is there a specific command that I can call so that it can play an audio file as part of a button press?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel Lightsaber Katana

Post by adafruit_support_bill »

Have you tried the example code from the tutorial? (You will need to use an FTDI cable for the Serial Monitor.)
https://learn.adafruit.com/adafruit-aud ... io-control

User avatar
korvorkian
 
Posts: 23
Joined: Tue Dec 02, 2014 12:47 pm

Re: Neopixel Lightsaber Katana

Post by korvorkian »

Hey guys, sorry i havent shown much progress on this, kinda just getting back to it.

I have the boards wired as such:
Pro_T--->AudioFX
11--------->RST
12--------->TX
13--------->RX

Pro_T--->Accel
A0------->Xout
A1 ------->Yout
A2------->Zout
A3------->ACT

and then a momentary switch on Pro_T 6, and the Neopixels on Pro_T 4.

Ive been digging through various source codes and for the life of me cant seem to figure out how to get the FX board to play a sound AND the neopixels to light up when I press the momentary switch.

Maybe its just my brain not seeing something that has to be simple after going through so many different bits of code from various sources. Ive added the code below where its at currently as my brain feels like mush and incase anyone wants to poke it/ knows a better way to activate the FX board.

Thanks guys!

Code: Select all

#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <Adafruit_Soundboard.h>
//soundboard ACT - A3
//RST - 11
//TX - 12
//RX - 13
 

#define PIN 4
#define BUTTON_PIN 6 
#define COLOR_ORDER GBR
#define CHIPSET     WS2811
#define NUM_LEDS 144       // Change to reflect the number of LEDs you have
#define maxsteps 16                                           // Case statement wouldn't allow a variable.
CRGBPalette16 currentPalette;
TBlendType    currentBlending;
/************ sound board setup ***********/
// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 12
#define SFX_RX 13
// Connect to the RST pin on the Sound Board
#define SFX_RST 11
#define SFX_ACT 3 // the 'ACT'ivity LED, to tell us if we're still playing
 
// You can also monitor the ACT pin for when audio is playing!
// we'll be using software serial
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
// pass the software serial to Adafruit_soundboard, the second
// argument is the debug port (not used really) and the third 
// arg is the reset pin
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
CRGB leds[NUM_LEDS];

// Parameter 1 = number of pixels in strip
// Parameter 2 = 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 strip = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);

//BUTTON SETUP STUFF
byte prevKeyState = HIGH; 

int ledMode = 0;  //FIRST ACTIVE MODE
int BRIGHTNESS = 255;    //0-255.  Lower number saves battery life, higher number is screamingly bright
int SATURATION = 255;    //0 is white (no color) and 255 is fully saturated with color
int HUE = 0;             //0-255, around the color wheel
int STEPS = 4;           //Wider or narrower bands of color
int SPEEDO = 5;         //The speed of the animation
                                      // Starting brightness.


void setup() 
{
  pinMode(BUTTON_PIN, INPUT_PULLUP);
 FastLED.addLeds<CHIPSET, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(  BRIGHTNESS );
  currentBlending = BLEND;
}
#define NUM_MODES 1
void loop() {
  
   switch (ledMode) {
                      case 0: colorWipe(strip.Color(255, 0, 0), 0); setupSound(SFX_RX);  break;
                      case 1: ReverseColorWipe(strip.Color(0, 0, 0), 0);  break;              
                     }  
 

       // button management section
        byte currKeyState = digitalRead(BUTTON_PIN); //REads Button_pin for state
     
        if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
            keyRelease();
        }
        prevKeyState = currKeyState;
        }
        
      void colorWipe(uint32_t c, uint8_t wait) {
      strip.begin();
      for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      
  }
      }
 void ReverseColorWipe(uint32_t c, uint8_t wait) {
  for(int i=(strip.numPixels()-1); i>=0; i--) {
      strip.setPixelColor(i, c);
      strip.show();
    
  }
}
void rainbowsaber(uint32_t c, uint8_t wait) 
{
  for(int i=(strip.numPixels()-1); i>=0; i--) {
      strip.setPixelColor(i, c);
      strip.show();
  }
}
//          // RAINBOW --------------------------------------------------
//        void Rainbow()
//        { 
//          FastLED.setBrightness(  BRIGHTNESS );
//          currentPalette = RainbowColors_p;
//          
//          static uint8_t startIndex = 0;
//          startIndex = startIndex + 1; 
//         
//         FillLEDsFromPaletteColors( startIndex);
//            
//          FastLED.show();
//          FastLED.delay(SPEEDO);  
//        }
       void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
  
  for( int i = 0; i < NUM_LEDS; i++) {
    leds[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);
    colorIndex += STEPS;
  }
}
   // SOLID COLOR -------------------------------------
     void Solid()
{
   fill_solid(leds, NUM_LEDS, CHSV(HUE, SATURATION, BRIGHTNESS));  
   FastLED.show(); 
}

  void setupSound(int pin) {
  pinMode(pin, OUTPUT);
  digitalWrite(pin, HIGH); // Set the pin high as the default state
}
 
void activateSound(int pin) {
  digitalWrite(PIN, HIGH);
  digitalWrite(pin, LOW); // bring the pin low to begin the activation
  /*
  According to the documentation, the Audio FX board needs 50ms to trigger. However,
  I've found that coming from my 3.3v Arduino Pro, it needs 100ms to get the trigger
  the going
  */
  delay(100); // hold the pin low long enough to trigger the board; may need to be longer for consistent triggering
  digitalWrite(pin, HIGH); //ring the pin high again to end the activation
  digitalWrite(PIN, LOW); 
}
 
 
//BUTTON CONTROL STUFF
// called when button is pressed
void shortKeyPress() {
    Serial.println("short");
    ledMode++;
    if (ledMode > NUM_MODES){
    ledMode=0; }
}
 
// called when key goes from pressed to not pressed
void keyRelease() {
    Serial.println("key release");
        shortKeyPress();
    }





Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”