From 3a5edaf1728c6ed925d27e3919e60f3179826663 Mon Sep 17 00:00:00 2001 From: Peter Hart Date: Sat, 29 Aug 2020 02:02:19 -0400 Subject: [PATCH] documenting main.py --- main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index b57bdd9..d8737f6 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import utime from mpu6050 import accel import picoweb +# Set Up Screen for output screen = {} screen['rst'] = Pin(16, Pin.OUT) screen['rst'].value(1) @@ -18,12 +19,14 @@ oled.fill(0) oled.text('Initializing',5,5) oled.show() +# Set up MPU communication mpu = {} mpu['scl'] = Pin(19, Pin.OUT, Pin.PULL_UP) mpu['sda'] = Pin(23, Pin.OUT, Pin.PULL_UP) mpu['i2c'] = I2C(scl=mpu['scl'], sda=mpu['sda']) accelerometer = accel(mpu['i2c']) +# Gets Date/Time, maps to EDT. def date_time(): (y,mo,d,wd,h,mi,s,*v) = RTC().datetime() (y,mo,d,h,mi,s,wd,yd) = utime.localtime(utime.mktime((y,mo,d,h,mi,s,wd,0))-4*3600) @@ -32,11 +35,13 @@ def date_time(): '%02d:%02d:%02d' % (h,mi,s) ) +# Get the network address of the Wireless Lan def ip(): return WLAN(STA_IF).ifconfig()[0] last_pos = 'UN' +# Get the current orientation of the 'dice' def position(x,y,z): global last_pos if abs(z) > 8192 and abs(y) < 4096 and abs(x) < 4096: @@ -60,6 +65,7 @@ def build_data(arg): 'position': position(x,y,z) } +# Write the current information to the screen def output_positions(data): oled.fill(0) oled.text('X: %(x)+05d' % data, 5, 5) @@ -72,15 +78,18 @@ def output_positions(data): oled.show() current_data = {} - + +# Function to update current data and display def run_cycle(): global current_data current_data = build_data(accelerometer.get_values()) output_positions(current_data) +# Here we're setting up a timer to call run_cycle every 1000ms (1s) timer = Timer(0) timer.init(period=1000, mode=Timer.PERIODIC, callback=lambda t:run_cycle()) +# This is setting up the web application to report values app = picoweb.WebApp('main') @app.route("/")