Leds and speakers controlled with Matlab

10 views (last 30 days)
Hi all! I want to write a Matlab code to emit tones and ligh under control by an external trigger signal. It's the first time I am doing this, and I am a bit lost. The tones will be produced by my laptops soundcard, and the ligh by LEDs. I have seen people using Arduino boards to control the LEDs, but I'd like to know if there's a simpler solution. The trigger signal will be processed with a PC card. Any help, recommended links or tutorials, possible solutions, ideas how to do this are more than welcome.
Thank you very much
  1 Comment
Daniel Shub
Daniel Shub on 28 Nov 2011
How many LEDs and how many channels of sound. How accurately do the LEDs need to be synced to the sound?

Sign in to comment.

Accepted Answer

Gergely Öllös
Gergely Öllös on 28 Nov 2011
Hi,
I suppose the simplest solution is to hook the LEDs to the LPT port and control it through the putvalue CMD. It’s fast enough to control hundreds of LEDs (if you serialize the data transfer). If you need to control up to 8 LEDs you can directly connect the LEDs to the LPT port through a single resistor/LED (then you can turn on/off these LEDs independently, without any serious hardware). There are additional ports on the LPT that you can use for additional LED control; these are the 4 ctrl (control) lines. You can use the putvalue CMD as for the 8 data lines (then you can control 12LEDs independently). The reason I mentioned them separately is that those lines are inverted (except INI). Here is the code that controls the 8 data lines and the 4 control lines:
warning('off', 'daq:digitalio:adaptorobsolete');
%Creating the digital I/O object
dio = digitalio('parallel','LPT1');
%Adding the lines to the object
daio = addline(dio,0:7,0,'out'); ctrl = addline(dio,0:3,2,'out');
%D0 D1 D2 D3 D4 D5 D6 D7
putvalue(daio,[0 1 0 1 0 1 0 1]); % Here every second led is lit.
%~TR ~AU INI ~SL
putvalue(ctrl,[1 1 0 1]); %Here every LED is off
The hardware: Connect to each led a 100ohm resistor. Connect the cathode (-) of each led to the GND (25. LPT pin). Each anode (+) connect to the following pins: DATA (pin 2., pin 3., pin 4., pin 5., pin 6., pin 7., pin 8., pin 9.), CONTROL (pin 1., pin 14., pin 16., pin 17.) and that’s all.
If you have trouble controlling the LPT port use the "FAST io32" object.
If you need to have a trigger (this not generates any interrupts) from outside (up to 5 sources) scan the input lines of the LPT port with the getvalue CMD.
stat = addline(dio,0:4,1,'in');
%ER SE PE AK ~BY
getvalue(stat);
INPUT PINS (pin 15, pin 13, pin 12, pin 10, pin 11 inverted)
I hope this helps, Gergo
  2 Comments
Daniel Shub
Daniel Shub on 28 Nov 2011
This solution requires the DAQ toolbox (and hence Windows). The standard serial port I/O should be able to do similar things with standard MATLAB on any platform. In all cases syncing the LEDs to the sound is going to be difficult.
Vicente
Vicente on 29 Nov 2011
Thank you very much Gergo and Daniel for your answer and comments.For the sound I just plan to use the two channels of my windows sound card. We just need a few leds or just one flashlight. Both sound and leds are activated with a trigger signal coming from a device.
I have the daq toolbox, and I will try understanding and implementing this solution.
Thank you verymuch

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 29 Nov 2011
I like the devices from Measurement Computing http://www.mathworks.com/products/daq/supportedio.html, like the PMD-1024LS. They're USB devices but they have other kinds too.

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!