Timed excel loop for serial port

2 visualizaciones (últimos 30 días)
Avichal
Avichal el 11 de Abr. de 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?

Respuestas (2)

Walter Roberson
Walter Roberson el 12 de Abr. de 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 el 17 de Abr. de 2013
Thanks! It worked!

Community Treasure Hunt

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

Start Hunting!

Translated by