matlab appdesigner UI 温湿度传感器例程

代码分了两个模块 UI 部分 和 数据传送部分
UI部分大部分有图形化的帮助 比较好操作 需要参考的建议直接用源文件看(代码详解有时间补上) 主要调用了appdesigner里的UI插件比如开关,指示灯之列的
其实大部分内容都不须要你自己去写 都是app designer 自动生成的

classdef main < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                 matlab.ui.Figure
        GridLayout               matlab.ui.container.GridLayout
        LeftPanel                matlab.ui.container.Panel
        connectorEditFieldLabel  matlab.ui.control.Label
        connectorEditField       matlab.ui.control.EditField
        connectButton            matlab.ui.control.Button
        disconnectButton         matlab.ui.control.Button
        IfTemp                   matlab.ui.control.CheckBox
        IfHumi                   matlab.ui.control.CheckBox
        TemperatureGaugeLabel    matlab.ui.control.Label
        TemperatureGauge         matlab.ui.control.LinearGauge
        HumidityGaugeLabel       matlab.ui.control.Label
        HumidityGauge            matlab.ui.control.LinearGauge
        ButtonGroup              matlab.ui.container.ButtonGroup
        TempC                    matlab.ui.control.RadioButton
        TempF                    matlab.ui.control.RadioButton
        STARTButton              matlab.ui.control.Button
        STOPButton               matlab.ui.control.Button
        Label                    matlab.ui.control.Label
        showT                    matlab.ui.control.NumericEditField
        Label_2                  matlab.ui.control.Label
        showF                    matlab.ui.control.NumericEditField
        PlotLabel                matlab.ui.control.Label
        CLabel                   matlab.ui.control.Label
        Label_3                  matlab.ui.control.Label
        RightPanel               matlab.ui.container.Panel
        UIAxes                   matlab.ui.control.UIAxes
        UITable                  matlab.ui.control.Table
        StatisticsLabel          matlab.ui.control.Label
        statusLampLabel          matlab.ui.control.Label
        statusLamp               matlab.ui.control.Lamp
        FileoperationLabel       matlab.ui.control.Label
        SaveDataButton           matlab.ui.control.Button
        LoadDataButton           matlab.ui.control.Button
        TempIndicatorLampLabel   matlab.ui.control.Label
        TempIndicatorLamp        matlab.ui.control.Lamp
        HumiIndicatorLampLabel   matlab.ui.control.Label
        HumiIndicatorLamp        matlab.ui.control.Lamp
        HEditFieldLabel          matlab.ui.control.Label
        HEditField               matlab.ui.control.NumericEditField
        TEditFieldLabel          matlab.ui.control.Label
        TEditField               matlab.ui.control.NumericEditField
        Label_4                  matlab.ui.control.Label
        CFLabel                  matlab.ui.control.Label
    end

    % Properties that correspond to apps with auto-reflow
    properties (Access = private)
        onePanelWidth = 576;
    end

    
    methods (Access = public)
        
        function UIconnected(app)
        
            app.disconnectButton.Enable = 'on';
            app.connectButton.Enable = 'off';
            app.connectorEditField.Enable = 'off';
            app.TempC.Enable = 'on';
            app.TempF.Enable = 'on';
            app.STARTButton.Enable = 'on';
            app.STOPButton.Enable = 'off';
            app.IfTemp.Enable = 'on';
            app.IfHumi.Enable = 'on';
            app.TemperatureGauge.Enable = 'on';
            app.HumidityGauge.Enable = 'on';
            app.UITable.Enable = 'on';
            app.statusLamp.Color = [1.00,0.00,0.00];
        end
    end
    
    methods (Access = private)
        
        function UIdisconnected(app)
            app.disconnectButton.Enable = 'off';
            app.connectButton.Enable = 'on';
            app.connectorEditField.Enable = 'on';
            app.TempC.Enable = 'off';
            app.TempF.Enable = 'off';
            app.STARTButton.Enable = 'off';
            app.STOPButton.Enable = 'off';
            app.IfTemp.Enable = 'off';
            app.IfHumi.Enable = 'off';
            app.TemperatureGauge.Enable = 'off';
            app.HumidityGauge.Enable = 'off';
            app.UITable.Enable = 'off';
            app.statusLamp.Color = [0.50,0.50,0.50];
            app.HumiIndicatorLamp.Color = [0.50,0.50,0.50];
            app.TempIndicatorLamp.Color = [0.50,0.50,0.50];
            app.SaveDataButton.Enable = 'off';

        end
    end
    

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            app.connectorEditField.Value = 'COM5';
            UIdisconnected(app);
            global IsinF;
            IsinF = false;
            app.UITable.Data = {0,0,0,0;0,0,0,0};
        end

        % Button pushed function: connectButton
        func
  • 5
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值