Here is the first post about my current project... A World of Warcraft Spellcaster costume for my son max. My son intends to trick or treat this year as his WoW character. I am building out various elements of the costume like and LED health bar (green) and mana bar (blue) that will "float" above his head. The bars will actually be in a black PVC harness that attaches to an old set of pee-wee football shoulder pads. I plan a few other features, such as high power blue LEDs (5-watt) in the palms of his hands so he can "cast spells".
I am building it on top of an arduino mega...
Here is a video of the health bar on my project bench:
Looks like you've got it working well. I look forward to seeing how the whole costume turns out, and to see the mana restoration potion and spells you were talking about today.
RE: WoW Spellcaster Costume... - yoyoboy - 09-21-200908:43 AM
Here is a another shot of the health bar, this time with additional red LEDs to indicate "low health".
I had Max hold it above his head to show the scale, I am now wondering if it is slightly too long (compared to the width of his shoulders). Maybe I should remove an LED segment from the end of the bar?
Well... Here it is, Max's final World Of Warcraft Spell Caster Costume. It's built from an Arduino Mega controlling the LED health bar, mana bar and spell casting glove. His fairy companion is made from an Arduino Pro 3.3V inside of a ball. The components came from a variety of sources; Sparkfun.com, RAELCO, Radio Shack, etc.
It was down to the wire to get it all put together by the 30th of October be we made it. We ended up removing several of the planned components from the final build, namely the fire-ball ignition mechanism and the P.O.V. runes that we had planned - oh well, there is always next year!
On a sad note; Max ended up sick with the Swine Flu and was unable to compete in his school's costume contest. So he wasn't able to win any prizes, but he did trick-or-treat the neighborhood on Halloween.
Code:
// 222222223333333333444444444455555
// 234567890123456789012345678901234
// R G G G G G G g g g g g g
// B B B B B B B B B B B B B
for (int i = 0; i < HB_COUNT; i++ ) {
pinMode(hb[i], OUTPUT);
}
for (int i = 0; i < MB_COUNT; i++ ) {
pinMode(mb[i], OUTPUT);
}
Serial.begin(19200);
Serial.println("Max Is The Wizard!");
Serial.println();
}
unsigned long rb_millis = 0;
int rb_state = 0;
const int RB_FLASH_DURATION = 400; // ms
int hbv = -1;
int mbv = -1;
int read_pot ( int pin )
{
unsigned long total;
total += analogRead( pin );
total += analogRead( pin );
total += analogRead( pin );
total += analogRead( pin );
total += analogRead( pin );
total += analogRead( pin );
total += analogRead( pin );
total += analogRead( pin );
return total / 8;
}
void loop()
{
int hb_pot = read_pot( HB_POT_PIN ); // full left = 1023, full right = 0
int curr_hbv = map( hb_pot, 1023, 0, 1, HB_COUNT - 1 );
int mb_pot = read_pot( MB_POT_PIN ); // full left = 1023, full right = 0
int curr_mbv = map( mb_pot, 1023, 0, 0, MB_COUNT - 1 );
if ( hbv != curr_hbv ) {
digitalWrite( rb, LOW );
hbv = curr_hbv;
for ( int i = 0; i < HB_COUNT; i++ ) {
digitalWrite( hb[i], i <= hbv ? HIGH: LOW );
}
}
if ( mbv != curr_mbv ) {
mbv = curr_mbv;
for ( int i = 0; i < MB_COUNT; i++ ) {
digitalWrite( mb[i], i <= mbv ? HIGH: LOW );
}
}
void Channel::fadeNow( uint8_t new_pwm, unsigned long duration ) {
fade( new_pwm, duration );
while( update() );
}
int Channel::update() {
unsigned long t = millis(); // Current Time
uint8_t y = my_pwm; // Current PWM
if ( t < x2 ) {
if ( t - x > interval ) {
while ( t - x > interval ) {
if ( y != y2 )
y += dir;
x += interval;
}
_pwm(y);
}
return 1; // More updates required
}
if ( y != y2 ) {
y = y2;
pwm( y );
}
return 0; // No more updates required
}
///////////////////////////////
class Bounce
{
public:
// Initialize
Bounce(uint8_t pin, unsigned long interval_millis );
// Sets the debounce interval
void interval(unsigned long interval_millis);
// Updates the pin
// Returns 1 if the state changed
// Returns 0 if the state did not change
int update();
// Forces the pin to signal a change (through update()) in X milliseconds
// even if the state does not actually change
// Example: press and hold a button and have it repeat every X milliseconds
void rebounce(unsigned long interval);
// Returns the updated pin state
int read();
// Returns the number of milliseconds the pin has been in the current state
unsigned long duration(void);
// Sets the stored pin state
void write(int new_state);
protected:
int debounce();
unsigned long previous_millis, interval_millis, rebounce_millis;
uint8_t state;
uint8_t pin;
};
Bounce::Bounce(uint8_t pin,unsigned long interval_millis)
{
interval(interval_millis);
previous_millis = millis();
state = digitalRead(pin);
this->pin = pin;
}
void Bounce::write(int new_state)
{
state = new_state;
digitalWrite(pin,state);
}
// We need to rebounce, so simulate a state change
if ( rebounce_millis && (millis() - previous_millis >= rebounce_millis) ) {
previous_millis = millis();
rebounce(0);
return 1;
}