import machine from pyb import Accel accel = Accel() print(accel.x(), accel.y(), accel.z(), accel.tilt())
from pyb import Accel, Servo servo = Servo(1) accel = Accel() while 1: servo.angle(accel.x(), 100) pyb.delay(200)
#hardware platform: pyboard V1.1 from pyb import Accel import time accel = Accel() #Accel is an object that controls the accelerometer. while True: time.sleep(0.1) print("x:%d, y:%d, z:%d" % (accel.x(), accel.y(), accel.z()))
from pyb import Accel from pyb import Gyro from pyb import Mag a = Accel(range=Accel.RANGE_8G) g = Gyro() m = Mag() while True: pyb.delay(1000) ax = a.x() ay = a.y() az = a.z() mx = m.x() my = m.y() mz = m.z() gx = g.x() gy = g.y() gz = g.z() print('-----') print(ax, ay, az) print(gx, gy, gz) print(mx, my, mz)
# MicroPython for the IOT - Chapter 6 # Example for working with the accelerometer on a Pyboard # Note: only works for the Pyboard! import pyb from pyb import Accel acc = Accel() print("Press CTRL-C to stop.") while True: pyb.delay(500) # Short delay before sampling print("X = {0:03} Y = {1:03} Z = {2:03}".format(acc.x(), acc.y(), acc.z()))