Skip to content

Instantly share code, notes, and snippets.

@plugwash
plugwash / tbit.py
Created December 14, 2019 14:56
tiny:bit motors and headlight LEDs from micropython.
from microbit import *
i2c.init()
def drive(left,right):2
if left > 255: left = 255
if left < -255: left = -255
if right > 255: right = 255
if right < -255: right = -255
if left > 0:
In the internal Java representation a String is a sequence of 16 bit "char"s representing UTF-16 code units.
.getBytes converts the string to a sequence of bytes according to a specific "charset".
The "UTF-16" charset encodes each UTF16 code unit as a pair of bytes which may be either big endian or little endian according to the platform. To mark which byte order is in use it prepends a "byte order mark".
The byte order mark is the unicode code point U+FFFE. When encoded in little endian bytes this comes out to "0xFE","0xFF" which when interpreted as signed twos-complement numbers display as "-2" "-1"
The "UTF-16LE" charset does not use a byte-order mark.