-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_adc.m
More file actions
36 lines (26 loc) · 986 Bytes
/
test_adc.m
File metadata and controls
36 lines (26 loc) · 986 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
%% Init
clear
clc
assert( ~isempty(which('IOPort')), '"IOPort" not found : check Psychtooblox installation => http://psychtoolbox.org/' )
% just to make sure all devices are closed
% only useful in case case of crash or development
IOPort('CloseAll')
%% Test
api = API_Arduino_IOPort(); % create empy object
api.Open();
% do several Pings : Arduino may take some time to be fully initialized
for i = 1 : 5
api.Ping();
end
channel = [0 1 2 3 4 5]; % index start at 0, and there are 5 ADC on my model from A0 to A5
for idx = 1 : length(channel)
channelVect = channel(1) : channel(idx); % to get several channels (if needed) in a single command
[value, dt] = api.GetAnalog(channelVect);
fprintf('took %1.3fms to fetch %d analog read \n', dt, length(channelVect))
end
% This is juste a "demo" command.
% If someone wants to add a feature, the Echo part on the cpp code is a good start.
api.Echo('hello');
api.Echo('much_longer_messsage!');
% cleanup
api.Close();