Arduino Lightsaber

DJWing79: I saw a video where with a specific model of buck-puck ( 3023-D-E-1000) you can drive an LED at 1000 ma and use the PWM pin from arduino connected to its control pin (on the buck) to dim the LED up and down. I need to find my second 3.7v battery to test...will let you know.

word. thanks. pwm will surely drop the vf. if that is the same model I read on. pwm 100% = full off 0 volts. make sure you don't think it's the opposite like a MOSFET.

wailer: Hello fellow builders,

I have been following this thread with great interest and decided to equip my homebuild saber with sound (finaly). Received parts yesterday so i can start building...

My question to JakeSoft, have you ever posted your your completed arduino code (with 335 swing sensor)?

I prefer to teach people how to fish.

JakeSoft: I prefer to teach people how to fish.

all fainess. this is a gallery thread. you never had to do anything after you dropped the mic. all the stuff you got going on with your led color mixing, menus, and audio is insane. I almost went all in and tried the mkIII clone. then I thought... Obiwan never changed colors, all clash is yellow or white flash in the films and sound is not tunable on these mystical weapons . good enough for me. and my expectations got managed just right.

still waiting for you (anyone) to teach me what the hell the WT int i++ code means. my arduino book says it is some progressing increment of some sort. maybe or can you at least translate it to English?. is the 8 arbitrary? etc... does it run just once? I am thinking it does. just whats in the loop runs over and over. right? or is every Wtsendcommand() running that bit? can the arduino really send data in micro seconds?

Dutch proverb: Better steal something that is good than create something that is bad. ;)

My local fish shop sells better fish than i could ever catch...

One more thing....

If ObiWan would not have given annakin's lightsaber to Luke, would Luke have become a Jedi or not...

Nobody can refuse a good lightsaber...

billpealer:
all fainess. this is a gallery thread. you never had to do anything after you dropped the mic. all the stuff you got going on with your led color mixing, menus, and audio is insane. I almost went all in and tried the mkIII clone. then I thought… Obiwan never changed colors, all clash is yellow or white flash in the films and sound is not tunable on these mystical weapons . good enough for me. and my expectations got managed just right.

still waiting for you (anyone) to teach me what the hell the WT int i++ code means. my arduino book says it is some progressing increment of some sort. maybe or can you at least translate it to English?. is the 8 arbitrary? etc… does it run just once? I am thinking it does. just whats in the loop runs over and over. right? or is every Wtsendcommand() running that bit? can the arduino really send data in micro seconds?

For (i = 0; i < 8; i++){
}

I is a variable so the arduino replaces it with the number it has on the moment it passes in the code.

I starts with 0 and i++ adds 1 (to i) every time the the loop passes until it reaches 8 then it ends or starts over again.
So if i reaches 8 you could put i back to 0 to run another loop or else the loop will end.
So the i used in the code changes every time the loop passes (first loop 0 second 1 next 2…)

The 8 is arbitrary if the loop has to run 8 times it could be any number…

In every arduino (or any other software) code there is a loop if not it would run the code once and then stop working

And “int” tells the arduino its a number.

https://www.arduino.cc/en/Reference/For

JakeSoft: He might be OK insofar as he won't cook anything. I seem to remember from an electronics course I took some years ago that it's not voltage that fries things, it's current. If the buck puck is limiting current to be within spec of the LED then the input voltage doesn't really matter as long as he is keeping it within the spec of what the buck puck can handle.

If the buck-puck says it can take 5V to 12V and will regulate current to 700ma, then you should be able to supply anything in that range and it'll still put out exactly 700ma and not fry the LED.

Completely right. I would only add, that most current control circuitry actually varies the voltage to make sure the current is constant. Reason is, it's easy to play with voltage. Usually then there is a shunt resistance to sense the current (convert the current to voltage again), and based on that sensed current (which is a voltage, lol), adjust the voltage to ensure the current is stable.

JakeSoft:
Here is some basic test code for you, Canobi. It’ll test all the I/O except for the accelerometer inputs. I couldn’t think of an easy way to do that except maybe putting out the raw read values via serial.

This code will ramp up all 6 possible LEDs to full power and then ramp them down one at a time. See code for the order they go in, but it’s more or less right around the pins on the Arduino in ascending order.

Then, once all the LEDs have been tested, it’ll go into “button test mode”. You can press the Activation switch, Aux switch, or bang the clash sensor to play three different sounds on the WT. Just program your WT588D in one-line serial mode to have three different sounds at 0x00, 0x01, and 0x02 so you’ll know if the right sound is playing when you hit the switches.

All while this is happening, the main LED light will light up or go out to indicate the status of the BUSY signal from the WT588D. If you hear sound, but the light does not change state then probably something wrong with the busy signal on the WT.

/*
  • Pins_Canobi.h : Defines pinout for Canobi’s 3-channel PCB.

*  Created on: Jan 8, 2016
*      Author: JakeSoft
*/

#ifndef PINS_CANOBI_H_
#define PINS_CANOBI_H_

//General I/O Pins
#define CLASH_PIN 2 //Clash sensor interrupt pin
#define LED_RED_PIN 3 //PWM output for RED LED
#define LED_GREEN_PIN 5 //PWM output for GREEN LED
#define LED_BLUE_PIN 6 //PWM output for BLUE LED
#define ACTIVATE_PIN 7 //Activation switch
#define AUX_PIN 8 //Aux switch
#define LED_FOC_PIN 9 //Flash-on-clash LED (not implemented by JakeSoft SW)
#define ACCENT1_PIN 10 //Accent LED
#define ACCENT2_PIN 11 //Secondary Accent LED (not implemented by JakeSoft SW)

//Serial pins for WT588d Sound board
#define WT588D_BUSY 12 //Module pin “LED/BUSY”
#define WT588D_SDA 13 //Module pin for DATA

//Accelerometer Pins
#define AXDL335_X_PIN A0 //X axis
#define AXDL335_Y_PIN A1 //Y axis
#define AXDL335_Z_PIN A2 //Z axis
#define AXDL335_VCC_PIN A3 //Accel power (not used by Canobi’s PCB)
#define AXDL335_GND_PIN A4 //Accel ground (not used by Canobi’s PCB)

#endif /* PINS_CANOBI_H_ */







/*

  • SaberTest.ino : Tests saber I/O

*  Created on: Jan 19, 2016
*      Author: JakeSoft
*/

#include “Pins_Canobi.h”

//Routine to send WT588D one-line serial commands
void WT588D_Send1(byte addr) {
    digitalWrite(WT588D_SDA, LOW);
    delay(5);

for(int i = 0; i < 8; i++)  {
        digitalWrite(WT588D_SDA, HIGH);
        if(bitRead(addr, i)) {
            delayMicroseconds(600);
            digitalWrite(WT588D_SDA, LOW);
            delayMicroseconds(200);
        } else {
            delayMicroseconds(200);
            digitalWrite(WT588D_SDA, LOW);
            delayMicroseconds(600);
        }
    }

digitalWrite(WT588D_SDA, HIGH);
    delay(10);
}

//Ramp up the LED then ramp it down
void TestLED(int PinNumber)
{
  //Ramp up the LED
  for(int LedPower = 0; LedPower < 255; LedPower++)
  {
    analogWrite(PinNumber, LedPower);
    delay(10);
  }
 
  //Ramp down the LED
  for(int LedPower = 255; LedPower > 0; LedPower–)
  {
    analogWrite(PinNumber, LedPower);
    delay(10);
  }
 
  //Ensure the the LED is fully off
  digitalWrite(PinNumber, LOW);
}

void setup()
{
  pinMode(LED_RED_PIN, OUTPUT);
  pinMode(LED_GREEN_PIN, OUTPUT);
  pinMode(LED_BLUE_PIN, OUTPUT);
  pinMode(LED_FOC_PIN, OUTPUT);
  pinMode(ACCENT1_PIN, OUTPUT);
  pinMode(ACCENT2_PIN, OUTPUT);
 
  pinMode(CLASH_PIN, INPUT);
  pinMode(ACTIVATE_PIN, INPUT);
  pinMode(AUX_PIN, INPUT);
 
  pinMode(WT588D_BUSY, INPUT);
  pinMode(WT588D_SDA, OUTPUT);
 
  pinMode(AXDL335_X_PIN, INPUT);
  pinMode(AXDL335_Y_PIN, INPUT);
  pinMode(AXDL335_Z_PIN, INPUT);
 
  //Set pull-up resistors for switches
  digitalWrite(CLASH_PIN, HIGH);
  digitalWrite(AUX_PIN, HIGH);
  digitalWrite(ACTIVATE_PIN, HIGH);
 
  //Run LED tests
  TestLED(LED_RED_PIN);
  TestLED(LED_GREEN_PIN);
  TestLED(LED_BLUE_PIN);
  TestLED(LED_FOC_PIN);
  TestLED(ACCENT1_PIN);
  TestLED(ACCENT2_PIN);

}

void loop()
{
  if(LOW == digitalRead(CLASH_PIN))
  {
    //Play a sound
    WT588D_Send1(0x00);
   
    delay(100);
    //Wait for user to let off the button
    while(LOW == digitalRead(CLASH_PIN)) {}
   
  }
 
  if(LOW == digitalRead(AUX_PIN))
  {
    //Play a sound
    WT588D_Send1(0x01);

delay(100);   
    //Wait for user to let off the button
    while(LOW == digitalRead(AUX_PIN)) {}
  }
 
  if(LOW == digitalRead(ACTIVATE_PIN))
  {
    //Play a sound
    WT588D_Send1(0x02);
   
    delay(100);
    //Wait for user to let off the button
    while(LOW == digitalRead(ACTIVATE_PIN)) {}
  }
 
  //Use the primary blade LED to indicate the status of the BUSY pin
  if(HIGH == digitalRead(WT588D_BUSY))
  {
    //Dimmly light the primary blade LED
    analogWrite(LED_RED_PIN, 64);
  }
  else
  {
    //Turn the primary blade LED off
    digitalWrite(LED_RED_PIN, LOW);
  }

}

Gone fishing and i think i caught something, dont know if it’s sprat or a bluefin tuna…
I’ll see when i gut it…

Just kidding, i just needed some code to get me started and this looks fine to me.

wailer: Gone fishing and i think i caught something, dont know if it's sprat or a bluefin tuna... I'll see when i gut it...

Just kidding, i just needed some code to get me started and this looks fine to me.

it will not help you with the ADXL

Protonerd: Completely right. I would only add, that most current control circuitry actually varies the voltage to make sure the current is constant. Reason is, it's easy to play with voltage. Usually then there is a shunt resistance to sense the current (convert the current to voltage again), and based on that sensed current (which is a voltage, lol), adjust the voltage to ensure the current is stable.

hook a car battery up to your buckpuck, don't PWM control it or analog potentiometer it,.. plug it into your blue luxeon. start the timer.

billpealer: it will not help you with the ADXL

I know, but i think i can can tackle that problem myself found some other example code that will get me started, should not be too hard. Will post examples as soon as i got it figured out.

If you wan't to teach people how to fish hand them a fishing rod :).

btw was my i++ explanation any help?

billpealer: hook a car battery up to your buckpuck, don't PWM control it or analog potentiometer it,.. plug it into your blue luxeon. start the timer.

If we are waiting for the LED to blow up, then we'll be waiting for a really long time. 12 volts is 12 volts, regardless of the source. Because science.

JakeSoft: If we are waiting for the LED to blow up, then we'll be waiting for a really long time. 12 volts is 12 volts, regardless of the source. Because science.

the buckpuck model in question is variable voltage based on the input. 7v in would yield 3.4v 700ma (according to luxdrive) 12v in would be,... more. this is from Luxdrives FAQ

"Can I input more voltage than my LEDs need or will that hurt my driver and/or LEDs?

Yes, you can input more voltage than your LED needs as long as it is in the driver range of 5-32VDC. It is best practice to use an input voltage that is closer to your needs. For example if your system ran around 7 volts, it is better to stick with the 12VDC than to use a 24VDC, whereas the 24VDC input would still work, it is better for the system overall if you used the closer value."

do you think the buckpuck can intelligently detect the MAX VF for any 3W LED and alter its voltage? If so,.. where does all the extra V go,?.. it's not being converted to A like most buck/boosts, that = heat on the puck. i was not interpreting that as the case from the above Q/A. 7v and 700ma will cook a 3W LED with passive cooling. 7v * 700ma = 4.9 Watt

stop judging me! |500x264

ok, here's another question....can I use one buckpuck to drive the constant amperage out at 1000 ma but not use the control pin (not getting a dimmer module) and instead have the Negative out feed through a N-FET gate like my current build...would that work? I haven't done my test yet, but I've heard the buckpucks don't generate heat in the same way a boost module would

billpealer: hook a car battery up to your buckpuck, don't PWM control it or analog potentiometer it,.. plug it into your blue luxeon. start the timer.

:) please read the manual: "The 3021/3023 Wide Range LED Power Module is a high efficiency dc to dc converter which delivers a fixed output current by varying the output voltage as required to maintain the specified current . A fast response current-sensing circuit permits the unit to be used in applications where flashing or pulsing of the LEDs is required."

I swear I did not, I simply have tons of experience with such circuits.

So been a minute on posting here, however the progress has not stopped.

I completely have redone my coding, using this for my switch and swing Click here. I was looking for who posted there code for the plasma saber, thanks for that! Did have to add a bit more coding to make the debounce work though.

I have worked out most my audio issues. Start up to Hum is seamless now, and was able to get rid of the 1700ms delay. Working on getting swing to be long enough to hear and switch to Hum seamlessly, only hangup i have now is getting the full swing to play quick enough for another swing, however i think a second sensor might help that. Also have my 3W Cree Blue LED hooked up. Will try and get a video soon.

Sample code:

else {
PlayComplete(2);
SABER_On = true;
Serial.println(“Saber is off, turning it on”);
for (int fadeValue = 30 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(LED_test, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
PlayLoop(1);

}
}
//Is a swing detected
if (SW_justpressed[1]) {
SW_justpressed[1] = 0;
if (SABER_On) {

Serial.println(“Swing detected”);
Serial.println(“Playing swing sound”);
PlayComplete(randNumber = random(3, 7));
delay(150);
PlayLoop(1);
}

Kdot: only hangup i have now is getting the full swing to play quick enough for another swing,

been working on this part, something about using the delay function to wait for the first sound to finish, is doing this. Need to replace this with a non-blocking delay... if anybody can come up with this solution please do share. :)

have you tried using millis?

purgedsoul: been working on this part, something about using the delay function to wait for the first sound to finish, is doing this. Need to replace this with a non-blocking delay... if anybody can come up with this solution please do share. :)

purgedsoul! thank you so much, i took the sample code you had posted previous and have been reworking that to fit my setup.

@DJWing79, i started to play with that, but was not 100% sure of what i was doing, but was kind of a side thought while working something else out

Sample code, wtd533 arduino library and even saber wave files can be found here https://github.com/ACDCLabs/WT588D.git Even a complete bin file that can be uploaded to the 533 directly is in the repository.

Too bad no accelerometer code, but hey my own code is slowly coming together. Thanks JakeSoft ahum....just kidding i mean Ecloud thanks for the fish man ;)