Timed excel loop for serial port

1 view (last 30 days)
Avichal
Avichal on 11 Apr 2013
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?

Answers (2)

Walter Roberson
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.

Avichal
Avichal on 17 Apr 2013
Thanks! It worked!

Community Treasure Hunt

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

Start Hunting!