# This version shows using the slider with Microdot to control the PWM.
# The project uses special tricks to avoid limitations of the files that you can store in Wokwi
import network
from microdot import Microdot
from machine import Pin, PWM, lightsleep
wlan = network.WLAN()
wlan.active(True)
wlan.connect('Wokwi-GUEST', '')
pwm0 = PWM(Pin(14), freq=5000, duty_u16=32768)
app = Microdot()
html = open("html.txt").read()
@app.route('/slider.js')
def script(request):
with open('slider_js.txt') as f:
js = f.read()
return js, 200, {'Content-Type': 'application/javascript'}
@app.route('/slider.css')
def script(request):
with open('slider_css.txt') as f:
js = f.read()
return js, 200, {'Content-Type': 'text/css'}
@app.route('/')
async def hello(request):
return html, 200, {'Content-Type': 'text/html'}
@app.route('/set')
async def set_value(request):
value = request.args.get('value', '0')
print(f"Slider set to: {value}")
pwm0.duty_u16(int(value))
return f"Received: {value}"
@app.route('/shutdown')
async def shutdown(request):
request.app.shutdown()
return 'The server is shutting down...'
app.run(debug=True,port=80)