Untitled
unknown
plain_text
a month ago
3.3 kB
0
Indexable
function BebekOdasiGUI % GUI Penceresi Oluşturma f = figure('Name', 'Bebek Odası İzleme Sistemi', 'NumberTitle', 'off', ... 'Position', [100, 100, 600, 400]); % Veri Görselleştirme Alanları uicontrol('Style', 'text', 'Position', [50, 340, 100, 20], ... 'String', 'Sıcaklık (°C)', 'HorizontalAlignment', 'center'); tempDisplay = uicontrol('Style', 'text', 'Position', [50, 310, 100, 30], ... 'String', '---', 'BackgroundColor', 'white', ... 'FontSize', 14); uicontrol('Style', 'text', 'Position', [250, 340, 100, 20], ... 'String', 'Nem (%)', 'HorizontalAlignment', 'center'); humidityDisplay = uicontrol('Style', 'text', 'Position', [250, 310, 100, 30], ... 'String', '---', 'BackgroundColor', 'white', ... 'FontSize', 14); uicontrol('Style', 'text', 'Position', [450, 340, 100, 20], ... 'String', 'Ses Seviyesi', 'HorizontalAlignment', 'center'); soundDisplay = uicontrol('Style', 'text', 'Position', [450, 310, 100, 30], ... 'String', '---', 'BackgroundColor', 'white', ... 'FontSize', 14); % Başlat Düğmesi startButton = uicontrol('Style', 'pushbutton', 'String', 'Başlat', ... 'Position', [250, 20, 100, 40], 'FontSize', 12, ... 'Callback', @startMonitoring); % Veri Değişkenleri temperatureData = []; humidityData = []; soundData = []; arduinoPort = []; % Arduino seri bağlantısı değişkeni % Başlatma Fonksiyonu function startMonitoring(~, ~) try % Arduino ile Seri Bağlantı if isempty(arduinoPort) arduinoPort = serial('COM3', 'BaudRate', 9600); % Portu kontrol edin fopen(arduinoPort); end % Verileri Okuma ve Görselleştirme while isvalid(f) if arduinoPort.BytesAvailable > 0 data = fscanf(arduinoPort, '%s'); tokens = regexp(data, 'Temperature: ([\d\.]+) C, Humidity: ([\d\.]+) %, Sound Level: (\d+)', 'tokens'); if ~isempty(tokens) temperature = str2double(tokens{1}{1}); humidity = str2double(tokens{1}{2}); soundLevel = str2double(tokens{1}{3}); % Verileri Güncelle set(tempDisplay, 'String', num2str(temperature)); set(humidityDisplay, 'String', num2str(humidity)); set(soundDisplay, 'String', num2str(soundLevel)); end end pause(0.1); end catch err disp('Bir hata oluştu: '); disp(err.message); end end % Pencere Kapatıldığında Seri Portu Kapat f.CloseRequestFcn = @closeGUI; function closeGUI(~, ~) if ~isempty(arduinoPort) fclose(arduinoPort); delete(arduinoPort); end delete(f); end end
Editor is loading...
Leave a Comment