Week 1 ยท Getting Started

Session 4: Types, maths and integer division

Teach & build120 minLesson 04: Sketch Structure, Variables & Types

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.

  1. Lesson 04: Choosing a type on the Uno
  2. Lesson 04: Syntax that trips beginners
  3. Theory Reference: Uno type summary
  4. Theory Reference: Arithmetic operators

Session plan

  1. 0:0010 min
    Recap

    Quiz: variables and scope

  2. 0:1020 min
    Demo

    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.

  3. 0:3060 min
  4. 1:3020 min
    Build

    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.

  5. 1:5010 min
    Wrap-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.