Serial Communication with aurduino using MATLAB

clear all
clc
answer=1; 
% this is where we'll store the user's answer

arduino=serial('COM19','BaudRate',9600); 
% create serial communication object on port %COM4

answer=input('Enter led value 1 or 2 (1=ON,2=OFF, 0=EXIT PROGRAM): ')

while(answer~=0)

fopen(arduino); 

% initiate arduino communication

answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): '); 

% ask user to enter value for variable answer

fprintf(arduino,'%s',char(answer));
 % send answer variable content to arduino 

fclose(arduino);
 % end communication with arduino


end

Comments