Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Lesson 10 activities. #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import time
import machine

led_power = machine.Pin(2, machine.Pin.OUT)
led_power.value(0)

sta_if = network.WLAN(network.STA_IF); sta_if.active(True)

try:
Expand All @@ -24,7 +27,7 @@

sta_if.connect(station, password)

for i in range(15):
for i in range(30):
print(".")

if sta_if.isconnected():
Expand All @@ -36,3 +39,16 @@
break
else:
print("Connection could not be made.\n")

if sta_if.isconnected():
print("Connected as: {}".format(sta_if.ifconfig()[0]))

led_wifi = machine.Pin(16, machine.Pin.OUT)

for i in range(3):
time.sleep(.5)
led_wifi.value(1)
time.sleep(.5)
led_wifi.value(0)


48 changes: 47 additions & 1 deletion web_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,57 @@ def dummy():

return response_template % body

pin = machine.Pin(10, machine.Pin.IN)
led = machine.Pin(9, machine.Pin.OUT)

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

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

def switch():
body = "{{state:{}}}".format(machine.Pin(10, machine.Pin.IN).value())
return response_template % body

adc = machine.ADC(0)

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

pwm = machine.Pin(13)
pwm = machine.PWM(pwm)
pwm.duty(1024)

def bright():
pwm.duty(0)
body = "The LED is bright."
return response_template % body

def medium_bright():
pwm.duty(500)
body = "The LED is medium brightness."
return response_template % body

def dim():
pwm.duty(1000)
body = "The LED is dim."
return response_template % body

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

def main():
Expand Down