examples/rainbow-compass/rainbow-compass.py
def raw_heading(minimums, maximums, zero=0):
    """Return a raw compass heading calculated from the magnetometer data."""

    X = 0
    Y = 2  # Change to 1 if you have the breakout flat

    # The range over which values will be calculated, i.e. -1 to +1
    mag_range = 2

    # Get the magnetometer's values
    mag = list(lsm.magnetometer())

    # Scale and shift values
    for i in range(len(mag)):
        mag[i] = ((mag_range / (maximums[i] - minimums[i])) * mag[i]) - \
                 (mag_range / 2.0)

    # Calculate the heading from the vector
    heading = math.atan2(mag[Y], mag[X])

    if heading < 0:
        heading += (2 * math.pi)

    # Convert radian value to degrees
    heading_degrees = (round(math.degrees(heading), 2) - zero) % 360

    return heading_degrees
Return a raw compass heading calculated from the magnetometer data.
Return a raw compass heading calculated from the magnetometer data.
Return a raw compass heading calculated from the magnetometer data .
def raw_heading(minimums, maximums, zero=0):
    X = 0
    Y = 2  
    mag_range = 2
    mag = list(lsm.magnetometer())
    for i in range(len(mag)):
        mag[i] = ((mag_range / (maximums[i] - minimums[i])) * mag[i]) - \
                 (mag_range / 2.0)
    heading = math.atan2(mag[Y], mag[X])
    if heading < 0:
        heading += (2 * math.pi)
    heading_degrees = (round(math.degrees(heading), 2) - zero) % 360
    return heading_degrees
def raw_heading ( minimums , maximums , zero = 0 ) : X = 0 Y = 2 mag_range = 2 mag = list ( lsm . magnetometer ( ) ) for i in range ( len ( mag ) ) : mag [ i ] = ( ( mag_range / ( maximums [ i ] - minimums [ i ] ) ) * mag [ i ] ) - ( mag_range / 2.0 ) heading = math . atan2 ( mag [ Y ] , mag [ X ] ) if heading < 0 : heading += ( 2 * math . pi ) heading_degrees = ( round ( math . degrees ( heading ) , 2 ) - zero ) % 360 return heading_degrees
Return a raw compass heading calculated from the magnetometer data.
Return a raw compass heading calculated from the magnetometer data .
"""Return a raw compass heading calculated from the magnetometer data.""" # Change to 1 if you have the breakout flat # The range over which values will be calculated, i.e. -1 to +1 # Get the magnetometer's values # Scale and shift values # Calculate the heading from the vector # Convert radian value to degrees
minimums
maximums
zero