Python pyb.Accel() Examples
The following are 6
code examples of pyb.Accel().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyb
, or try the search function
.
Example #1
Source File: alevel.py From micropython-nano-gui with MIT License | 6 votes |
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)
Example #2
Source File: sensor_demo.py From uble with MIT License | 6 votes |
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)
Example #3
Source File: accelusbmidi.py From micropython-stm-lib with MIT License | 5 votes |
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)
Example #4
Source File: bluest_protocol.py From uble with MIT License | 5 votes |
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)
Example #5
Source File: apoll.py From micropython-async with MIT License | 5 votes |
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
Example #6
Source File: apoll.py From micropython-async with MIT License | 5 votes |
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