AP CSP CodeX - Mission 11: Spirit Level
Mission 11: Spirit Level
Students read the CodeX accelerometer and draw a moving bubble on the display to build a digital spirit level.
Overview
During this mission, students build a digital spirit level. They read the CodeX accelerometer, convert the reading to degrees with the math library, and draw lines and a circle on the display to show the position of the CodeX. After Objective 6, students create a function with a return value, a good reminder of how useful abstraction can be.
🎯 Mission Goal: Students will use a graphical display to show the position of the CodeX, based on reading the accelerometer.
Learning Targets
- I can use code to read the CodeX accelerometer.
- I can convert an accelerometer reading to degrees.
- I can use functions from the math library.
- I can use built-in functions to draw lines and circles on the display screen.
Key Concepts
- Meet the accelerometer. There's one in your cell phone, and in many other devices we use.
- Make sure students read the accelerometer toolbox entry!
- Convert units generated by the accelerometer into degrees.
- Use a bit o' math for scaling the degrees to a range suitable for the moving "bubble".
- The CodeX screen is a graphical user interface and can display lines, circles and text.
Assessment Opportunities
- Mission 11 Assignment
- Spirit_Level program
- Mission 11 Kahoot! Review
Success Criteria
- Read data from the accelerometer
- Convert data to degrees
- Draw lines on the display screen
- Use data from the accelerometer to draw a circle
- Create and call a function with a return
Digital Resources
- ▸Mission 11 Assignment
- ▸Mission 11 Kahoot! Review
- ▸Code Solutions and Assignment Answers - Teacher Dashboard > Educator Resources button
Classroom Materials
- ▸CodeX
- ▸USB-C cable
- ▸Computer
- ▸Physical spirit level (for the warm-up)
Real-World Applications
- Cell phone screen rotation
- Fitness app step counter
- Airbag deployment in vehicles
- Electronic stability control in vehicles
- Smart watches that have fall detection
- Earthquake and structural tracking
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
AP CSP Framework
- The assignment is best completed digitally. Prepare the assignment to give through your LMS.
- Bring a physical spirit level to class for the warm-up.
- If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
- Encourage the students to do as much code on their own as they can, and use CodeTrek to check their work, or as a hint when needed.
- The assignment adds an extra step to complete after Objective 6, before turning in the program.
- If you have time at the end of the lesson, use the Mission 11 Kahoot! Review.
- Refer to the lesson plans in the Python with CodeX Mission Pack Curriculum for additional challenges, cross-curricular suggestions, and additional information.
Lesson Outline
This outline gives the narration for one way to present the lesson.
Bring a physical level to school and show it to the students. Discuss how a mechanical spirit level works. The "spirit" is a liquid with space for a bubble, which will be in the center of the tube when it is horizontal. Today's program will create a digital level using the CodeX and its accelerometer.
Randomly group students into pairs for pair programming (or they can work individually).
Students log in to one computer. Two computers can be used if they want to have the assignment open on one computer and CodeSpace on the other computer.
Students go to make.firialabs.com and should be at the beginning of Mission 11.
draw_line() and draw_circle() for the first time. Students can fill the screen with any color and then draw lines and circles on the screen. There is a bit of reading on this objective so students can understand how the simple graphics work and the orientation of the screen.NOTE: If displaying on a screen, using a BLACK fill and WHITE lines is easier to see.
Here are all the commands students could use. These will be used in a future lesson. See the CodeX canvas documentation for details.
-
draw_line(x1, y1, x2, y2, color=(255, 255, 255)) -
fill_rect(x1, y1, width, height, color=(255, 255, 255))
-
fill_circle(x, y, radius, color=(255, 255, 255)) -
fill(color)
-
draw_text(text, scale=1, color=(255, 255, 255), background=None, x=0, y=0) -
draw_rect(x1, y1, width, height, color=(255, 255, 255))
✅ The assignment is complete and ready to turn in.
You can discuss with students other applications for the CodeX accelerometer. Let them brainstorm ideas.
Optional. Use a formative assessment for the wrap-up.
Formative assessment:
- Daily reflection journal
- Mission 11 Kahoot! Review (in class or individual)
- Exit ticket or group review on the accelerometer, tuples, or other topics used in the lesson