''' Mission 11 - Spirit Level - Remix 1C - Mild The remix challenge is to use the y value for tilt and the bubble instead of the x value. The lines being drawn need to be horizontal instead of vertical. ''' from codex import * from time import sleep import math # center of display (240 x 240) CENTER = 120 # draw two lines on the screen # leave space in the middle for the circle display.fill(WHITE) display.draw_line(0, CENTER, 105, CENTER, BLACK) display.draw_line(135, CENTER, 239, CENTER, BLACK) # define a variable to use for the circle's position y = CENTER # start an infinite loop while True: # read from the accelerometer and get x value val = accel.read() tilt_y = val[1] # change accelerometer reading to degrees scaled = (tilt_y / 16384) scaled = min(max(scaled, -1), 1) degrees = math.asin(scaled) * 180 / math.pi degrees = int(degrees) # erase current circle, recalculate, and draw new circle display.draw_circle(CENTER, y, 15, WHITE) y = CENTER + degrees display.draw_circle(CENTER, y, 15, ORANGE) sleep(0.5)