Timed excel loop for serial port
2 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 12 Apr 2013
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 Comments
See Also
Categories
Find more on Spreadsheets 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!