import dash
from dash import html, dcc
from dash.dependencies import Input, Output
import dash_daq as daq
# Initialize the Dash app
app = dash.Dash(__name__)
# Define the app layout
app.layout = daq.DarkThemeProvider(
children=html.Div(
style={
'backgroundColor': '#1a1a1a',
'color': '#e0e0e0',
'textAlign': 'center',
'fontFamily': '"Droid Sans", "Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif',
'padding': '50px'
},
children=[
html.Div(
daq.Knob(
id='my-knob',
min=0,
max=100,
value=0,
color={"default": "#FFDD44"},
size=150,
style={
'backgroundColor': '#333',
'borderRadius': '50%',
'padding': '20px',
'display': 'inline-block',
'margin': '20px'
}
)
),
html.Div(
[
daq.LEDDisplay(
id='my-led-1',
value="0",
color="#FFDD44",
backgroundColor="#444",
style={
'borderRadius': '10px',
'padding': '10px',
'margin': '5px',
'display': 'inline-block',
'textAlign': 'center'
}
),
daq.LEDDisplay(
id='my-led-2',
value="0",
color="#FFDD44",
backgroundColor="#444",
style={
'borderRadius': '10px',
'padding': '10px',
'margin': '5px',
'display': 'inline-block',
'textAlign': 'center'
}
),
daq.LEDDisplay(
id='my-led-3',
value="0",
color="#FFDD44",
backgroundColor="#444",
style={
'borderRadius': '10px',
'padding': '10px',
'margin': '5px',
'display': 'inline-block',
'textAlign': 'center'
}
),
daq.LEDDisplay(
id='my-led-4',
value="0",
color="#FFDD44",
backgroundColor="#444",
style={
'borderRadius': '10px',
'padding': '10px',
'margin': '5px',
'display': 'inline-block',
'textAlign': 'center'
}
),
daq.LEDDisplay(
id='my-led-5',
value="0",
color="#FFDD44",
backgroundColor="#444",
style={
'borderRadius': '10px',
'padding': '10px',
'margin': '5px',
'display': 'inline-block',
'textAlign': 'center'
}
)
],
style={'display': 'flex', 'justifyContent': 'center', 'marginBottom': '50px'}
),
daq.ToggleSwitch(
id='reset-switch',
value=False,
color="#FFDD44",
label="Reset to Zero",
labelPosition="top",
style={'margin': '20px'}
)
]
)
)
# Define the callback to update the LEDs based on the knob value and reset switch
@app.callback(
[Output('my-led-1', 'value'),
Output('my-led-2', 'value'),
Output('my-led-3', 'value'),
Output('my-led-4', 'value'),
Output('my-led-5', 'value')],
[Input('my-knob', 'value'),
Input('reset-switch', 'value')]
)
def update_leds(knob_value, reset_switch):
if reset_switch:
return ["0", "0", "0", "0", "0"]
else:
# Scale the knob value to fit within the range 00000 to 99999
scaled_value = int((knob_value / 100) * 99999)
# Format the scaled value as a 5-digit string with leading zeros
formatted_value = f"{scaled_value:05d}"
return list(formatted_value)
# Run the server
if __name__ == '__main__':
app.run_server(debug=True)