编程语言
首页 > 编程语言> > 基于python的环境噪声实时监测系统

基于python的环境噪声实时监测系统

作者:互联网

一 系统简介 1.简介 该系统可以实时显示噪声量大小,并进行一段时间的噪声统计。 2.特性 二 源码解析   1.噪声分贝的实时更新: 这里的分贝值是仿真的,后续用实际替换即可。
def update_data():
    global sec_n
    sec_n = sec_n + 1
    db_val = random.randint(30,40)

    time_ax.append(sec_n)
    db_ay.append(db_val)

    dpg.set_value('series_tag', [time_ax, db_ay])
    dpg.set_item_label('series_tag', "nosie val:"+str(db_val)+":db")

2.噪声分贝的定时:

    timer = threading.Timer(timer_max_val,time_func)
    timer.start()

3. 整体源码:

import dearpygui.dearpygui as dpg
from math import sin, cos
import time,threading
import random

dpg.create_context()

time_ax = []
db_ay = []


def update_data():
    global sec_n
    sec_n = sec_n + 1
    db_val = random.randint(30,40)

    time_ax.append(sec_n)
    db_ay.append(db_val)

    dpg.set_value('series_tag', [time_ax, db_ay])
    dpg.set_item_label('series_tag', "nosie val:"+str(db_val)+":db")

def time_func():
    #update_series()
    update_data()
    timer_max_val = 1
    print("timer is occured")
    timer = threading.Timer(timer_max_val,time_func)
    timer.start()
with dpg.window(label="Noise DB", tag="win"):
    #dpg.add_button(label="Update Series", callback=update_series)
    # create plot
    timer_max_val = 1
    sec_n = 0
    timer = threading.Timer(timer_max_val,time_func)
    timer.start()
    with dpg.plot(label="Line Series", height=400, width=400):
        # optionally create legend
        dpg.add_plot_legend()
        # REQUIRED: create x and y axes
        dpg.add_plot_axis(dpg.mvXAxis, label="x")
        dpg.set_axis_limits(dpg.last_item(), 0, 2000)
        dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="y_axis")
        dpg.set_axis_limits(dpg.last_item(), 0,100)

        # series belong to a y axis
        dpg.add_line_series(time_ax, db_ay, label="nosie db", parent="y_axis", tag="series_tag")

dpg.create_viewport(title='Environment Detection', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
  三 总结   1.效果展示:  

 

标签:val,python,series,db,实时,dpg,环境噪声,timer,time
来源: https://www.cnblogs.com/dylancao/p/16244179.html