documenting main.py
This commit is contained in:
parent
bd05b3dd02
commit
3a5edaf172
9
main.py
9
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)
|
||||
@ -73,14 +79,17 @@ def output_positions(data):
|
||||
|
||||
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("/")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user