LED and Switch Display Board

Hello, Im a newbie with the arduino board, so I'm still learning, and excuse my ignorance. Basically I'm trying to design a display board that will light a series of leds when a button is pushed and also will allow the computer to play a specific video. I think the hardware part i got, I'm going to wire the leds in parallel and use a 220 ohm resister between every three. The leds are 20mA and have a voltage of 2.4. then I would hook the series of leds up to a push button switch (spdt) I just want the button to turn on the leds and then and the video. I looked at the Shift example in tutorial and I decided to buy some CD4021BE shift registers for the buttons and just use that example to wire the thirteen buttons. My problem is getting the ocmputer to interface with the buttons. Is this setup even right? I'm thinking about using processing to play the individual videos but I'm lost with that aspect. Please help :'(

I'm thinking about using processing to play the individual videos but I'm lost with that aspect.

Have you looked at any of the Processing examples? Processing can interact with the serial port, and can play movies.

The Arduino can write to the serial port ("Play MovieA").

My problem is getting the ocmputer to interface with the buttons.

The what? The computer can not interface with the buttons. That's the Arduino's job. The Arduino can send data (information or commands) to the serial port that the computer can read.

The leds are 20mA and have a voltage of 2.4.

I don't think you've read the data sheet right. LEDs need current limiting resistors in series with them because they are NOT current limiting devices. An LED acts like a short circuit and will draw unlimited amperage, limited only by the ability of the power supply.

The leds are 20mA and have a voltage of 2.4

Maybe that should been "voltage DROP"?

See....

http://www.arunet.co.uk/tkboyd/ele1led.htm

... for discussion of LEDs and their current limiting resistors.

The voltage is the operating voltage or forward voltage. See data sheet http://www.mouser.com/catalog/specsheets/83013.pdf. I have looked at processing examples but i can't find examples of it opening a movie based on which button was pressed on the arduino. Looking at button press examples I think I can figure out the programing for the 13 buttons to switch on their series of leds but I don't know if processing can also make a movie play at the same time. If you have any advice or examples please help. I'm using the CD4021BE to operate the thirteen switch inputs and an LED driver for the led outputs (1-5) for each switch. Also any push button recommendations? I don't want to over load the chip. :D

@lissy2010

I’d suggest you start out with something a little less ambitious. Perhaps just try making it so: when you press a button on the arduino it sends a command to processing and then have something on the screen change accordingly. Then move forward and figure out how to have processing send commands back and make videos. Then once you figure it out, scale it up.

As for all the fuss about the LEDs, I don’t see what the big deal is. The specs you posted are completely legitimate. 20mA @ 2.4V… The thing is, you will have to use a series dropping resistor in order to limit the current so its within the tolerable range of 20mA.
V = voltage
I = current (in Amps)
R = resistance (in ohms)

V = I*R or R = V / I

I < 20mA
V = 5v - 2.4v = 2.6v
now… R > 2.6 / 20mA WRONG! mA HAS TO BE in Amps. Just divide by 1000 (there are 1000mA in one A). So… R > 2.6 / 0.02 = 130 ohms. Any resistor above 130ohm should be ok.

Yes I was planning on using a 220 ohm resister, for the leds. The hardware I'm not so much worried about anymore, I am an EE (maybe a rusty one) but I can figure out the wiring. Its the coding I need help with. I have this so far for the processing code...its not really anything. I know that will load multiple movies but i just need help modifying it based on opening a movie based on the button press.

void setup() { size(640, 480, P3D); background(0);

movie1 = new GSMovie(this, "station.mov"); movie1.loop();

movie2 = new GSMovie(this, "station.mov"); movie2.loop();

movie3 = new GSMovie(this, "station.mov"); movie3.loop();

movie4 = new GSMovie(this, "station.mov"); movie4.loop();

movie5 = new GSMovie(this, "station.mov"); movie5.loop();

movie6 = new GSMovie(this, "station.mov"); movie6.loop();

movie7 = new GSMovie(this, "station.mov"); movie7.loop();

movie8 = new GSMovie(this, "station.mov"); movie8.loop();

movie9 = new GSMovie(this, "station.mov"); movie9.loop();

movie10 = new GSMovie(this, "station.mov"); movie10.loop();

movie11 = new GSMovie(this, "station.mov"); movie11.loop();

movie12 = new GSMovie(this, "station.mov"); movie12.loop();

movie13 = new GSMovie(this, "station.mov"); movie13.loop(); }

void movieEvent(GSMovie movie) { movie.read(); }

void draw() { tint(255, 20);

image(movie1, mouseX-movie1.width/2, mouseY-movie1.height/2); image(movie2, mouseY-movie2.height/2, mouseX-movie2.width/2); image(movie3, mouseY-movie3.height/2, mouseX-movie3.width/2); image(movie4, mouseY-movie4.height/2, mouseX-movie4.width/2); image(movie5, mouseY-movie5.height/2, mouseX-movie5.width/2); image(movie6, mouseY-movie6.height/2, mouseX-movie6.width/2); image(movie7, mouseY-movie7.height/2, mouseX-movie7.width/2); image(movie8, mouseY-movie8.height/2, mouseX-movie8.width/2); image(movie9, mouseY-movie9.height/2, mouseX-movie9.width/2); image(movie10, mouseY-movie10.height/2, mouseX-movie10.width/2); image(movie11, mouseY-movie11.height/2, mouseX-movie11.width/2); image(movie12, mouseY-movie12.height/2, mouseX-movie12.width/2); }

For the arduino code i was just goiing to modify the shiftin example http://arduino.cc/en/Tutorial/ShftIn12 So that it also turns on the LEDs outputs per reading the button press inputs. :-/ I hope that this is right

Please any help is appreciated...i was never a programmer :'(

I know you think you have the LEDs sorted but you haven't:-

I'm going to wire the leds in parallel and use a 220 ohm resister between every three.

You can't do that with LEDs they are non liner devices if they are to be wired in parallel you need a resistor for each LED.

i was never a programmer

Yes, well you have to communicate between the arduino and processing using the serial port. So you do a serial write at the arduino end and a serial read at the processing end. Then use a switch statement or lots of if statements to see what you have read from the arduino and decide what movie to use. Sorry but your code isn't even close.

Next time you post code use the # button in the reply box so it is contained in a scrollable box.

@Grumpy_Mike

I’m sorry I meant series, I’m not going to be using so many leds now so I can wire 3 or 4 leds in series with a resistor to protect it. I know if your going to be using more than 5 resistors its probably a better idea to put them in parallel like i saw here http://i510.photobucket.com/albums/s344/fleakiller/LED.jpg

and sorry about the code

I hope it works this time

For the arduino reading the shift register something like this

void setup() {
  //start serial
  Serial.begin(9600);

  //define pin modes
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);
  pinMode(ledPin, OUTPUT);      // declare LED as output

}

void loop() {

  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin,1);
  //set it to 1 to collect parallel data, wait
  delayMicroseconds(20);
  //set it to 0 to transmit data serially  
  digitalWrite(latchPin,0);


  switchVar1 = shiftIn(dataPin, clockPin);
  if (switchVar1 == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin1, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH); // turn LED ON
 
    Serial.println(switchVar1, BIN);

  for (int n=0; n<=12; n++)
  {
    if (switchVar1 & (1 << n) ){
      //print the value of the array location
      Serial.println(note2sing[n]);
    }
  }

//white space
Serial.println("-------------------");
//delay so all these print satements can keep up. 
delay(500);

}

byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);

  for (i=12; i>=0; i--)
  {
    digitalWrite(myClockPin, 0);
    delayMicroseconds(0.2);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      //set the bit to 0 no matter what
      myDataIn = myDataIn | (1 << i);
    }
    else {
    pinState = 0;
    }

    //Debuging print statements
    //Serial.print(pinState);
    //Serial.print("     ");
    //Serial.println (dataIn, BIN);

    digitalWrite(myClockPin, 1);

  }
  //debuging print statements whitespace
  //Serial.println();
  //Serial.println(myDataIn, BIN);
  return myDataIn;
   }
}
]

And for processing to read the serial and then play a movie…um i still don’t really know how to do but the serial part is this

import processing.serial.*;

Serial myPort;  
int val;      // Data received from the serial port

void setup() 
{
  size(640, 480, P3D);
  
  String portName = Serial.list()[0];
  myPort = new Serial(this, COM5, 9600);
}

Use the command:- cnc.bufferUntil(10); // call serialEvent every line feed just after the myPort = new Serial(this, COM5, 9600); Then when ever a new value is sent from the arduino this routine will automatically be called:-

void serialEvent(Serial myPort) {  // this gets called everytime a line feed is recieved
  String received = myPort.readString() ;  
   println(received + " from serial port");
  receivedNumber= int(received);
}
 int receivedNumber;

then in the draw loop of processing look at the value of the receivedNumber variable to see if it has been changed from last time. If it has then go to a switch structure and use it to play the movie corresponding to the number you have received.