%% MATLAB Code for Serial Communication between Arduino and MATLAB %% INITIALIZE THE SERIAL CONNECTION WITH ARDUINO if ~isempty(instrfind) fclose(instrfind); delete(instrfind); end x=serial('COM3','BAUD', 9600); fopen(x); go = true; %% TO PRINT OUT THE BEAT OF A SONG sound(d,r); pause(0.200); % Need to play around with this value to get the desired pause for n = 1:length(intensity) pause(0.0999); % Need to play with this value fprintf(x, '%s\n', intensity(1,n)); end %% TO PRINT OUT A SIN WAVE % t = linspace(0,500,2000); % y = 255.*(sin(0.406.*t) + 1)./2; % y = fix(y); % tic; % for n = 1:length(t) % y(1,n); % %fprintf(x,'%i',y(1,n)); % fprintf(x,y(1,n)); % pause(0.001); % end % toc; %% TO PRINT OUT A CUSTOM INTENSITY THRU SERIAL % while go % % a= input('Enter an intensity from [0,255]'); % % % if (a <0 || a>255) % % go=false; % % end % % g = sprintf('%s', 'g', a); % fprintf(x,g); % end