필터 지우기
필터 지우기

Data Acquisition (Really easy question)

조회 수: 3 (최근 30일)
Shaun VanWeelden
Shaun VanWeelden 2012년 12월 28일
I am trying to write a couple functions to interact with a MCC 1208LS sensor board and specifically trying to turn an led bar with 8 different lights on or off. I have made a function that does this, but it is slow as molasses and I know for a fact there is a better way, I just don't know what it is.
I have my function below and I am looking for a more speedy/optimal/less-sketchy way to code it. Thanks for the help! If I need to add comments I can do so, otherwise I think my goal is extremely intuitive.
if true
function [] = putDigitalData(ledNums, value)
%Sets state of LED light board
global dioLine
DIO = digitalio('mcc','0');
if isempty(dioLine)
dioLine = addline(DIO,0:7,1,'out');
end
for i=1:length(ledNums)
putvalue(dioLine(ledNums(i)),value)
end
end
end

채택된 답변

Pedro Villena
Pedro Villena 2012년 12월 28일
global dioLine ledsLine
DIO = digitalio('mcc','0');
if isempty(dioLine)
dioLine = addline(DIO,0:7,1,'out');
ledsLine = [0 0 0 0 0 0 0 0];
end
ledsLine(ledNums) = value;
putvalue(dioLine,ledsLine);

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 12월 28일
Whenever possible, initialize digitalio and addline outside of any loop, so that the function you call only outputs values and does not have to construct the lines.

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by