Monday, July 16, 2012

Button Activated EL Wire Prototype






Just trying to figure out the options for having my students this year program EL Wire for a dance performance, I wanted to find out if a momentary switch activated EL Wire costume would work. So I worked out a prototype, really just enough to make sure the wiring and programming would be feasible. It was easier than I expected. As a jumping off point I used a fantastic LadyAda Arduino switch tutorial that really explains things well. I still couldn't get the concept of a pull-down or pull-up resistor through my thick head but reading about it again in McRoberts' Beginning Arduino finally made it sink in.
The pics show that individual as well as multiple switch presses work. What my students will do if they want to pursue this idea is sew the switches into gloves and the wires into black outfits for a choreographed dance in the dark.
Here's the code:
UPDATE: The first version is all you need as I learned after making this discovery.
int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {3,4,5};              // same with switch pins

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
  }
}

void loop(){
}
This version is only needed if you use different pins for input and output:
int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {6,7,8};              // same with switch pins
int val[3];                        // variable for reading the pin status

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
    val[i] = 0;                    // Set val array to 0
  }
}

void loop(){
  for(int i = 0;i<3;i++) {
    val[i] = digitalRead(switchPin[i]);   // read input values and store it in val array
    if (val[i] == HIGH) {               // check if any buttons are pressed
      for(int i = 0;i<3;i++) {
        digitalWrite(wirePin[i], HIGH);   // turn wire on in same array index
      }
  }
    if (val[i] == LOW) {              // check if buttons are not pressed
      for(int i = 0;i<3;i++) {
        digitalWrite(wirePin[i], LOW);    // turn wires off
      }
    }
  }
}

2 comments :

tieandjeans said...

That looks great! Is that a spark fun board that you're using as an EL Inverter? What are your thoughts to turning that I to something wearable?

Erik N. said...

thanks! Yes, the El Escudo Dos is from Sparkfun, as are the wires, which have the the JST connectors on already, and the inverter (3V). The next thing I have to figure out is wiring the switches from glove fingers to the board, where to put the board, etc. It can all be powered by a 9V I connected to a 2.1mm barrel plug, so it's portable. It's going to make an awesome Halloween costume.