Start a new topic

Shaky Ball

from microbit import *

import random

import math


#convert

def convert_accel_to_grid(accel):

    # x and y accel are -1024 to 1024 so make positive

    accel = accel + 1024 

    # divide into grid position

    grid = int(accel / (2048.0 /5.0))

    # ensure the range matches the grid size

    if(grid > 4):

        grid = 4

    if(grid < 0):

        grid = 0

    return grid


while True:

    tiltX = convert_accel_to_grid(accelerometer.get_x())

    tiltY = convert_accel_to_grid(accelerometer.get_y())

    

    #clear and set the display

    display.clear()

    display.set_pixel(tiltX, tiltY, 9)


2 people like this idea
Login or Signup to post a comment