''' Mission 11 - Remix 1B - Mild This remix adds an intro and ending to the program. In this solution, the intro is a function, but it doesn't have to be. This solution also includes the functions from Remix 1A -- The remix challenge is to create a function from existing code. This solution shows two functions (set_screen and calc_degrees). ''' 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[] # 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.draw_circle(x, CENTER, 15, WHITE) x = CENTER + degrees display.draw_circle(x, CENTER, 15, ORANGE) sleep(0.5) if buttons.was_pressed(BTN_B): break # ending message display.clear() display.print("DONE", scale=6)