Timed excel loop for serial port
4 次查看(过去 30 天)
显示 更早的评论
I am trying to create a MATLAB program using an excel sheet with 500 values below 10, and 500 values above 10, a total of 1000 values. I need the program to read the values in a 10 second loop. Every time it reads values below ten it should send a signal of "1" to the serial port, and every time it reads the values above 10 it should send a signal of "0" to the serial port. How should I write this?
0 个评论
回答(2 个)
Walter Roberson
2013-4-12
num = xlsread('YourFile.xls');
s = serial('COM1');
fopen(s);
for K = 1 : length(num)
thisval = num(K);
signaltosend = 1;
if thisval > 10; signaltosend = 0; end
fwrite(s, signaltosend, 'uint8');
pause(10);
end
fclose(s);
If you need '1' and '0' instead of 1 and 0, then the change is straight-forward.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!