Week 1 ยท Getting Started
Session 4: Types, maths and integer division
Learning outcomes
- Choose byte, int, long, float and bool for Uno values
- Explain integer division and use % for the remainder
- Recognise int overflow on the 16-bit Uno
- Convert a count to a value with float maths
Kit and components
- Uno, USB cable and lab PC
Pre-reading about 25 min
Students read these on their phones before class. They are listed on the student Before class page.
Session plan
- 0:0010 minRecap
Quiz: variables and scope
- 0:1020 minDemo
Why 5 / 2 is 2
Show integer and float division, then % in a seconds-to-minutes example. Print 60 * 1000 stored in an int and watch it come out negative.
- 0:3060 minCode Along
Types and maths
Ask students to predict each result before pressing Test.
- 1:3020 minBuild
Types on the real Uno
Students upload a sketch that prints sizeof(int), sizeof(long) and sizeof(float), plus an overflowing int, and compare the results with the Uno type summary.
- 1:5010 minWrap-up
One sentence per type
Each student writes when they would use byte, int, long, float and bool.
Checkpoint: ready to move on?
Students can predict 7 / 2, 7 % 2 and 7.0 / 2, and choose a type that can hold a millis() value.
Extension for fast finishers
Catch-up path
Repeat Share out the sweets with the hints, then do three / and % examples on paper.
Homework and practice
Code Along 2.5-2.7.
Facilitator notes
- Seconds to hours, minutes and seconds is the hardest core exercise so far. It is fine for it to spill into homework.