From 7ac80ea4bcba07542e78a04cd22d1e42a0b6196d Mon Sep 17 00:00:00 2001 From: Alexander Boone Date: Wed, 6 May 2020 22:49:46 -0700 Subject: [PATCH] Initial Commit --- flexible_web_server/main.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/flexible_web_server/main.py b/flexible_web_server/main.py index d1855c1..946a292 100644 --- a/flexible_web_server/main.py +++ b/flexible_web_server/main.py @@ -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():