本文整理汇总了Python中pyb.Accel方法的典型用法代码示例。如果您正苦于以下问题:Python pyb.Accel方法的具体用法?Python pyb.Accel怎么用?Python pyb.Accel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyb
的用法示例。
在下文中一共展示了pyb.Accel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Accel [as 别名]
def main():
print('alevel test is running.')
CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
wri.set_clip(True, True, False)
acc = pyb.Accel()
dial = Dial(wri, 5, 5, height = 75, ticks = 12, bdcolor=None,
label='Tilt Pyboard', style = Dial.COMPASS, pip=YELLOW) # Border in fg color
ptr = Pointer(dial)
scale = 1/40
while True:
x, y, z = acc.filtered_xyz()
# Depending on relative alignment of display and Pyboard this line may
# need changing: swap x and y or change signs so arrow points in direction
# board is tilted.
ptr.value(-y*scale + 1j*x*scale, YELLOW)
refresh(ssd)
utime.sleep_ms(200)
示例2: acc_update
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Accel [as 别名]
def acc_update(self):
#accel = pyb.Accel()
#axis_x, axis_y, axis_z = accel.x(), accel.y(), accel.z()
axis_x, axis_y, axis_z = (
urandom.randint(0, 32767) % X_OFFSET,
urandom.randint(0, 32767) % Y_OFFSET,
urandom.randint(0, 32767) % Z_OFFSET)
buffer = ustruct.pack(
"<HHH",
axis_x, axis_y, axis_z)
result = self.aci_gatt_update_char_value(
serv_handle=self.acc_serv_handle,
char_handle=self.acc_char_handle,
char_val_offset=0,
char_value_len=len(buffer),
char_value=buffer).response_struct
if result.status != BLE_STATUS_SUCCESS:
raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
result.status))
log.debug("aci_gatt_update_char_value %02x", result.status)
示例3: main
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Accel [as 别名]
def main():
import pyb
serial = pyb.USB_VCP()
midi = MidiOut(serial, channel=1)
switch = pyb.Switch()
if hasattr(pyb, 'Accel'):
accel = pyb.Accel()
SCALE = 1.27
else:
from staccel import STAccel
accel = STAccel()
SCALE = 127
while True:
while not switch():
pyb.delay(10)
note = abs(int(accel.x() * SCALE))
velocity = abs(int(accel.y() * SCALE))
midi.note_on(note, velocity)
while switch():
pyb.delay(50)
midi.note_off(note)
示例4: accgyromag_update
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Accel [as 别名]
def accgyromag_update(self):
# accel = pyb.Accel()
# acc_axis_x, acc_axis_y, acc_axis_z = accel.x(), accel.y(), accel.z()
tick = utime.time()
acc_axis_x, acc_axis_y, acc_axis_z = (
urandom.randint(0, 32767) % X_OFFSET,
urandom.randint(0, 32767) % Y_OFFSET,
urandom.randint(0, 32767) % Z_OFFSET)
gyto_axis_x, gyto_axis_y, gyto_axis_z = (
urandom.randint(0, 32767) % X_OFFSET,
urandom.randint(0, 32767) % Y_OFFSET,
urandom.randint(0, 32767) % Z_OFFSET)
mag_axis_x, mag_axis_y, mag_axis_z = (
urandom.randint(0, 32767) % X_OFFSET,
urandom.randint(0, 32767) % Y_OFFSET,
urandom.randint(0, 32767) % Z_OFFSET)
buffer = ustruct.pack(
"<HHHHHHHHHH",
tick,
acc_axis_x, acc_axis_y, acc_axis_z,
gyto_axis_x, gyto_axis_y, gyto_axis_z,
mag_axis_x, mag_axis_y, mag_axis_z)
result = self.aci_gatt_update_char_value(
serv_handle=self.hw_serv_handle,
char_handle=self.acc_gyro_mag_bluest_char_handle,
char_val_offset=0,
char_value_len=len(buffer),
char_value=buffer).response_struct
if result.status != status.BLE_STATUS_SUCCESS:
raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
result.status))
log.debug("aci_gatt_update_char_value %02x", result.status)
示例5: accel_coro
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Accel [as 别名]
def accel_coro(timeout = 2000):
loop = asyncio.get_event_loop()
accelhw = pyb.Accel() # Instantiate accelerometer hardware
await asyncio.sleep_ms(30) # Allow it to settle
accel = Accelerometer(accelhw, timeout)
while True:
result = accel.poll()
if result == 0: # Value has changed
x, y, z = accel.vector()
print("Value x:{:3d} y:{:3d} z:{:3d}".format(x, y, z))
elif accel.timed_out(): # Report every 2 secs
print("Timeout waiting for accelerometer change")
await asyncio.sleep_ms(100) # Poll every 100ms
示例6: accel_coro
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Accel [as 别名]
def accel_coro(timeout = 2000):
accelhw = pyb.Accel() # Instantiate accelerometer hardware
await asyncio.sleep_ms(30) # Allow it to settle
accel = Accelerometer(accelhw, timeout)
while True:
result = accel.poll()
if result == 0: # Value has changed
x, y, z = accel.vector()
print("Value x:{:3d} y:{:3d} z:{:3d}".format(x, y, z))
elif accel.timed_out(): # Report every 2 secs
print("Timeout waiting for accelerometer change")
await asyncio.sleep_ms(100) # Poll every 100ms