Arduino inside a Mario Costume

by djmacatack on Mon Oct 05, 2009 12:36 am

Hey guys,

I just put together a costume project using a Wave shield. I don't need help with anything but since I bought everything from Adafruit I thought I'd share. Note that I'm new here so I don't know the forum etiquette.

http://www.youtube.com/watch?v=zj-I0zMkIQk

The code is not very clean because it was recycled from a previous failed project that used more LED's. I used some creative looping to save text space.

Code: Select all
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"

#define DEBOUNCE 20

#define swPin 14
int value = 255;   
int ledpin[] = {18,19,6,7,8}; //5 output pins declared 1 used
AF_Wave card;
File f;
Wavefile wave;

void setup() {
  byte i;
  digitalWrite(ledpin[1], LOW);//Default off
  Serial.begin(9600);
  for (byte i = 2; i <= 5; ++i) {
    pinMode(i, OUTPUT);
  }
  for (byte i = 1; i <= 5; ++i) {
    pinMode(ledpin[i], OUTPUT);
  }
  for (byte i = swPin + 1; i <= swPin + 3; ++i) {
    digitalWrite(i, HIGH);
  }

  if (!card.init_card()) {
    putstring_nl("Card init failed!"); return;
  }
  if (!card.open_partition()) {
    putstring_nl("No partition!"); return;
  }
  if (!card.open_filesys()) {
    putstring_nl("Couldn't open filesys"); return;
  }
  if (!card.open_rootdir()) {
    putstring_nl("Couldn't open dir"); return;
  }
}

void loop() {   
  switch (check_switches()) {
    case 2:
    {
      playfile(picker(0,1));
      while (wave.isplaying)
      {
        shot();
      }
      break;
    }
    case 3:
    {
      playfile(picker(1,8));
       while (wave.isplaying)
      {

      }
      break;
    }
    case 4:
      playfile(picker(8,11));
  }
}

void shot()
{

      digitalWrite(ledpin[1], HIGH);   
      delay(200);                 
      digitalWrite(ledpin[1], LOW); 
      delay(100);

}
byte check_switches()
{
  static byte previous[6];
  static long time[6];
  byte reading;
  byte pressed;
  byte index;
 
  for (index = 0; index < 6; ++index) {
    reading = digitalRead(swPin + index);
    if (reading == LOW && previous[index] == HIGH && millis() - time[index] > DEBOUNCE)
    {
      time[index] = millis();
      pressed = index + 1;
      break;
    }
    previous[index] = reading;
  }
  return (pressed);
}
char* picker(int low, int high)
{
  char* str[]={"FIREBALL.WAV", "JUMP1.WAV", "JUMP2.WAV", "JUMP3.WAV", "JUMP4.WAV", "JUMP5.WAV", "JUMP6.WAV", "JUMP6.WAV", "SONG1.WAV", "SONG2.WAV", "SONG3.WAV"};
  int i = random(low, high);
  return str[i];
}
void playfile(char *name) {
  if (wave.isplaying) {
    wave.stop();
  }
  if (f) {
    card.close_file(f);
  }
  f = card.open_file(name);
  if (f && wave.create(f)) {
    wave.play();
  }
}
djmacatack
 
Posts: 4
Joined: Mon Oct 05, 2009 12:22 am

Re: Arduino inside a Mario Costume

by adafruit on Mon Oct 05, 2009 11:59 am

damn that is WAY COOL!!!
User avatar
adafruit
 
Posts: 11511
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Arduino inside a Mario Costume

by djmacatack on Fri Oct 30, 2009 5:40 pm

Hey and thanks for the blog mention awhile back. I wanted to post a vid of the finished product. Enjoy.

http://www.youtube.com/watch?v=oiWxle-KvHg
djmacatack
 
Posts: 4
Joined: Mon Oct 05, 2009 12:22 am

Re: Arduino inside a Mario Costume

by adafruit on Fri Oct 30, 2009 6:29 pm

<- LMAO :lol:
User avatar
adafruit
 
Posts: 11511
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc