Leds and speakers controlled with Matlab
조회 수: 5 (최근 30일)
이전 댓글 표시
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
Daniel Shub
2011년 11월 28일
How many LEDs and how many channels of sound. How accurately do the LEDs need to be synced to the sound?
채택된 답변
Gergely Öllös
2011년 11월 28일
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
Daniel Shub
2011년 11월 28일
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.
추가 답변 (1개)
Image Analyst
2011년 11월 29일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Input and Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!