Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions flexible_web_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,37 @@ def dummy():

return response_template % body

pin = machine.Pin(9, machine.Pin.OUT)

def light_on():
pin.value(1)
body = "You turned a light on!"
return response_template % body

def light_off():
pin.value(0)
body = "You turned a light off!"
return response_template % body

switch_pin = machine.Pin(10, machine.Pin.IN)

def switch():
body = "{state: " + str(switch_pin.value()) + "}"
return response_template % body

adc = machine.ADC(0)

def light():
body = "{value: " + str(adc.read()) + "}"
return response_template % body

handlers = {
'time': time,
'dummy': dummy,
'light_on': light_on,
'light_off': light_off,
'switch': switch,
'light': light,
}

def main():
Expand Down