#!/usr/bin/env python3
"""This example shows how to use the Joystick Click wrapper of the LetMeCreate.

It continuously reads the position of the joystick, prints it in the terminal
and displays a pattern on the LED's based on the x coordinate.

The Joystick Click must be inserted in Mikrobus 1 before running this program.
"""

from letmecreate.core import i2c
from letmecreate.core import led
from letmecreate.click import joystick

OFFSET = 98
MAXIMUM = OFFSET2

def get_led_mask(perc):
	div = int((1. - perc)led.LED_CNT)
	if div > led.LED_CNT:
		div = led.LED_CNT

	mask = 0
	for i in range(div):
		mask |= (1 << i)

	return mask

i2c.init()
led.init()

while True:
	pos = joystick.get_position()
	print('{} {}'.format(pos[0], pos[1]))
	mask = get_led_mask(float(pos[0] +  OFFSET)/float(MAXIMUM))
	led.switch_on(mask)
	led.switch_off(~mask)

i2c.release()
led.release()

#!/usr/bin/env python3
"""This example shows how to use the Joystick Click wrapper of the LetMeCreate.

It continuously reads the position of the joystick, prints it in the terminal
and displays a pattern on the LED's based on the x coordinate.

The Joystick Click must be inserted in Mikrobus 1 before running this program.
"""

from letmecreate.core import i2c
from letmecreate.core import led
from letmecreate.click import joystick

OFFSET = 98
MAXIMUM = OFFSET2

def get_led_mask(perc):
    div = int((1. - perc)led.LED_CNT)
    if div > led.LED_CNT:
        div = led.LED_CNT

    mask = 0
    for i in range(div):
        mask |= (1 << i)

    return mask

i2c.init()
led.init()

while True:
    pos = joystick.get_position()
    print('{} {}'.format(pos[0], pos[1]))
    mask = get_led_mask(float(pos[0] +  OFFSET)/float(MAXIMUM))
    led.switch_on(mask)
    led.switch_off(~mask)

i2c.release()
led.release()

Replace tabs by space in example
joystick: Replace tabs by space in example

Signed-off-by: Francois Berder <59eaf4bb0211c66c3d7532da6d77ecf42a779d82@outlook.fr>
