Here is the relevant part from the Appdesigner (file is attached) :
methods (Access = private)
function displayCharacteristicData(app)
app.Lamp.Color = 'green';
% Lamp not green
[data,timestamp] = read(src,'oldest');
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: ScanButton
function ScanButtonPushed(app, event)
devicelist = blelist("Timeout", 5);
i = 1;
while(i <= length(devicelist.Index))
app.HRSensorListDropDown.Items{i} = devicelist.Name{i};
i = i + 1;
end
end
% Button pushed function: ConnectButton
function ConnectButtonPushed(app, event)
model = app.HRSensorListDropDown.Value;
chestbelt = ble(model);
hr_char = characteristic(chestbelt,"Heart Rate","Heart Rate Measurement");
hr_char.DataAvailableFcn = @displayCharacteristicData;
% app.Lamp.Color = 'green';
end