-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunArduino.m
More file actions
43 lines (39 loc) · 905 Bytes
/
Copy pathRunArduino.m
File metadata and controls
43 lines (39 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
% clear
% clc
%
% answer=5; % this is where we'll store the user's answer
arduino=serial('COM4','BaudRate',9600); % create serial communication object on port COM4
fopen(arduino); % initiate arduino communication
try
pause(5);
% value = '5';
%fprintf(arduino, '%s', value); % send answer variable content to arduino
fwrite(arduino, '9');
value = 'eached';
read = '';
tic
while strcmp(read, value) == 0 && toc < 5 %While not the same (with a backup timer)
read = fscanf(arduino, '%s', 14);
end
%pause(4);
fwrite(arduino, '1');
pause(4);
fwrite(arduino, '5');
pause(4);
fwrite(arduino, '6');
pause(10);
% fwrite(arduino, '9');
% pause(4);
% fwrite(arduino, '2');
% pause(2);
% fwrite(arduino, '5');
% pause(2);
% fwrite(arduino, '6');
% pause(10);
% fwrite(arduino, '9');
% pause(4);
fclose(arduino);
catch me
fclose(arduino); %Make absolutely sure this is closed
end
%delete(arduino);