''' Mission 11 - Remix 2A - Medium This remix changes the bubble indicator to a solid circle when degrees is 0, which means perfectly centered. It is based off of Remix 1B, which adds an intro and ending to the program, but it is not part of the challenge. ''' 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 def set_screen(): display.fill(WHITE) display.draw_line(CENTER, 0, CENTER, 105, BLACK) display.draw_line(CENTER, 135, CENTER, 239, BLACK) def calc_degrees(): global degrees # read from the accelerometer and get x value val = accel.read() tilt_x = val[0] # change accelerometer reading to degrees scaled = (tilt_x / 16384) scaled = min(max(scaled, -1), 1) degrees = math.asin(scaled) * 180 / math.pi degrees = int(degrees) def intro(): display.print("Spirit Level") display.print("") display.print("A to start") display.print("B to quit") while True: if buttons.was_pressed(BTN_A): break # define a variable to use for the circle's position x = CENTER intro() set_screen() # start an infinite loop while True: calc_degrees() # erase current circle, recalculate, and draw new circle display.fill_circle(x, CENTER, 15, WHITE) x = CENTER + degrees if degrees == 0: display.fill_circle(CENTER, CENTER, 15, RED) else: display.fill_circle(CENTER, CENTER, 15, WHITE) display.draw_circle(x, CENTER, 15, ORANGE) sleep(0.2) if buttons.was_pressed(BTN_B): break # ending message display.clear() display.print("DONE", scale=6)