Go Down

Topic: Arduino Lightsaber (Read 105906 times) previous topic - next topic

Canobi

Oh yeh, and a vertical USB mini B socket extention board for the charger which allows for installing the socket away from the mainboard:


The large hole up top is for an M3 mounting screw, the two down the bottom by the output solder pads are for passing the wires through.

jenga67

#1186
Feb 20, 2017, 01:28 am Last Edit: Feb 20, 2017, 01:52 am by jenga67
Hello everyone! I have started my lightsaber project and I'd like to say thank you for this thread!

I'm trying to make my sound code work with WT588D-U 16m in 1-line serial mode, but i can not overcome sound ticking. I put up a small video
Could anyone please give me some help, send me to the right direction?

I have re-read this topic and particulary the page 8, but it doesn't help.
Started with only pwer-on sound, at least to make it work and then add others.
Here is what i'm using for my light/sound triggering:

Code: [Select]
#define WT588D_SDA 8
byte file_count = 1;
int button =2;
int LED = 9;

void setup() {
 
pinMode(button,INPUT_PULLUP);
pinMode(LED,OUTPUT);
pinMode(WT588D_SDA, OUTPUT);


void loop () {
if (button == HIGH) {
 digitalWrite(LED,HIGH);
 WT588D_Send_Command(0x00);
 while(button==LOW){}
 }
else{
 digitalWrite(LED,LOW);
 }
delay(100);


The load process to WT went fine, binary compiled ok and load was successfull.

I apologize for my noobness, guys, but seems i'm totally stuck.

JakeSoft

Hello everyone! I have started my lightsaber project and I'd like to say thank you for this thread!

I'm trying to make my sound code work with WT588D-U 16m in 1-line serial mode, but i can not overcome sound ticking. I put up a small video
Could anyone please give me some help, send me to the right direction?

I have re-read this topic and particulary the page 8, but it doesn't help.
Started with only pwer-on sound, at least to make it work and then add others.
Here is what i'm using for my light/sound triggering:

Code: [Select]
#define WT588D_SDA 8
byte file_count = 1;
int button =2;
int LED = 9;

void setup() {
 
pinMode(button,INPUT_PULLUP);
pinMode(LED,OUTPUT);
pinMode(WT588D_SDA, OUTPUT);


void loop () {
if (button == HIGH) {
 digitalWrite(LED,HIGH);
 WT588D_Send_Command(0x00);
 while(button==LOW){}
 }
else{
 digitalWrite(LED,LOW);
 }
delay(100);


The load process to WT went fine, binary compiled ok and load was successfull.

I apologize for my noobness, guys, but seems i'm totally stuck.

I assume you are using a latching switch? If so, that's fine, but your code need to realize when it's already sent the command and not try to do it again. Your WT588D is being bombarded with a play command each time your processor cycles. That's why it's "ticking", the sound is restarting over and over. Set up a flag in your code to keep track of if your saber is on or not. Use it to prevent sending new commands if you've already done so.

jenga67

Thanks for your reply Jake!

I have realized the problem now, will try to fix this one and post a video of my saber when its done ;)


jenga67

#1189
Feb 22, 2017, 02:24 am Last Edit: Feb 22, 2017, 02:31 am by jenga67
Hi everyone, its me again  :smiley-confuse:

I have fixed my on/off/hum sounds, they trigger fine, but i have some issues with swing sound now.
For debounce I try to use Arduino Switch tutorial with my tilt sensor.

When I give arduino power, swing sound in some positions of tilt sensor triggers like a machinegun.
Here is a video.
Could you please give me a hint on what i'm doing wrong?

Here is my code:
Code: [Select]
int swing = 7;
int previous = LOW;
int reading;
long time = 0;
long debounce = 300;
bool swingsound;

setup()
pinMode(swing,OUTPUT);
digitalWrite(swing,HIGH);
swingsound = false;

loop(){
reading = digitalRead(swing);
if (reading == HIGH && previous == LOW && millis() - time > debounce){
    swingsound = true;
    WT588D_Send_Command(2);
    delay(100);
  }else{
    swingsound = false;
  }
 previous = reading;
}


Big thanks!

billpealer

#1190
Feb 22, 2017, 05:42 pm Last Edit: Feb 22, 2017, 08:11 pm by billpealer
Try this.  I don't think u need the "previous' value,..  this tute is more for a on/off button. i just plugged this into my WT on a bread board and it worked fine for the roller ball sensor. Dont forget to save the time thru the loop  "  time = millis(); "
Code: [Select]
long debounce = 150;

loop(){
reading = digitalRead(swing);
if (reading == HIGH && reading == LOW && millis() - time > debounce){
 
swingsound = false;  // do nothing.   
   delay(50);
 }
else
{
   swingsound = true;
WT588D_Send_Command(2);
delay(150);  //wait a tick so swings don't rapid fire.
 }
time = millis();
}

you can even add this to get swings to fire when inverting the trigger, and make a different sound.

Code: [Select]
long debounce2 = 200;

if (reading == LOW && reading == HIGH && millis() - time > debounce2){
 
swingsound = false;  // do nothing.   
   delay(50);
 }
else
{
   swingsound = true;
WT588D_Send_Command(3);  // make a different swing sound
delay(150);  //wait a tick so swings don't rapid fire.
 }
time = millis();
}

jenga67

#1191
Feb 22, 2017, 11:06 pm Last Edit: Feb 22, 2017, 11:38 pm by jenga67
Billpealer hi!

Thanks a lot for your reply!
I have discarded "previous" completely and made sure I define time as millis() in the end of the loop.
But, it's playing like a machine gun, doesn't matter HIGH or LOW, just start continous play on power-up.

That is probably wrong, but just a guess, can it be that i'm putting my swing sensor on a pin that can not be debounced?

But for the logic, as I understand it, if there is a change of state on sensor and time passed since last swing is more than debounce time, sound should be played, otherwise do nothing until condition above, please correct me if i'm wrong.

 
Code: [Select]

int swing = 7;
int reading;
long time = 0;
long debounce = 200;
bool swingsound;

setup(){
pinMode(swing,OUTPUT);
digitalWrite(swing,HIGH);
swingsound = false;

loop(){
reading = digitalRead(swing);

if(reading == HIGH && reading == LOW && millis() - time > debounce)
{
  swingsound = false;
}
else
{
 swingsound = true;
  WT588D_Send_Command(2);
  delay(150);
}
time = millis();
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy