當前位置: 首頁>>代碼示例>>Python>>正文


Python pyb.Accel方法代碼示例

本文整理匯總了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) 
開發者ID:peterhinch,項目名稱:micropython-nano-gui,代碼行數:20,代碼來源:alevel.py

示例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) 
開發者ID:dmazzella,項目名稱:uble,代碼行數:22,代碼來源:sensor_demo.py

示例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) 
開發者ID:SpotlightKid,項目名稱:micropython-stm-lib,代碼行數:29,代碼來源:accelusbmidi.py

示例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) 
開發者ID:dmazzella,項目名稱:uble,代碼行數:35,代碼來源:bluest_protocol.py

示例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 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:15,代碼來源:apoll.py

示例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 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:14,代碼來源:apoll.py


注:本文中的pyb.Accel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。