Year 9 · Summer 1

Physical Computing · Lesson 2 of 5

Inputs: buttons, light and temperature

PracticalTopic 1 What a computer isTopic 13 Programming basics

Year 9 · Physical Computing · Lesson 2 of 5

You will learn to

  • Use digitalRead to read a button, and explain why the button needs a pull-down resistor.
  • Write an if that turns the light on only while the button is pressed.
  • Read the TMP36 sensor with analogRead and turn the reading into °C with the formula.
  • Explain what an ADC does: it turns a voltage into a number from 0 to 1023.

Year 9 · Physical Computing · Lesson 2 of 5

Success criteria

You have got it when you can say:

  • I can make a button change the light.
  • I can turn a reading of 153 into about 24.7 °C, step by step.
  • I can make the warning light come on above 30 °C.

Year 9 · Physical Computing · Lesson 2 of 5

Retrieval starter

Questions from before. Write your answers, then show them.

  1. Last lesson

    Why does an LED need a resistor?

    A To make it a different colourB To limit the current so it doesn't burn outC To store electricity

    B. To limit the current so it doesn't burn out

  2. Last unit

    Turning a wave into numbers is done by…

    A An ADCB A DAC

    A. An ADC

  3. Earlier this year

    The program runs but gives the wrong answer. That's a…

    A Syntax errorB Logic errorC Runtime error

    B. Logic error

Year 9 · Physical Computing · Lesson 2 of 5

Key words (1 of 4)

casting
Changing a value from one data type to another, like int("13").
Input / output
Anything that gets information into the computer. Keyboard, mouse, touchscreen, microphone, camera, a temperature sensor.
Process
The computer follows instructions to change that information. Add two numbers. Move a character. Sort a list. The CPU does this.

Year 9 · Physical Computing · Lesson 2 of 5

Key words (2 of 4)

Transistor
An electronic switch with no moving parts.
Hardware
The physical parts of a computer.
Software
Programs: instructions that tell hardware what to do.
Embedded system
A small computer built into a device for one job.

Year 9 · Physical Computing · Lesson 2 of 5

Key words (3 of 4)

Variable
A named place in memory that holds a value.
Assignment
Storing a value in a variable. = in Python, ← in pseudocode.
Concatenation
Joining strings together: "7" + "7" = "77".
Selection
Choosing a path with if / else.

Year 9 · Physical Computing · Lesson 2 of 5

Key words (4 of 4)

Iteration
Repeating steps: a loop.
Boolean
A value that is only True or False.
Infinite loop
A loop whose condition never becomes false.

The explanation · step 1 of 2 · part 1 of 2

Input, process, output

  1. Input: it receives information. You press a key, a microphone hears a sound.
  2. Process: it follows instructions to change that information. Add numbers, move a game character.
  3. Output: it gives a result back. Letters on a screen, sound from a speaker.
★Remember

Most computers also do storage: they keep information to use later.

The explanation · step 1 of 2 · part 2 of 2

Input, process, output (continued)

e.g.Example

A washing machine is a computer too. Input: the dial. Process: choose a wash plan. Output: the drum turns.

The explanation · step 2 of 2

Input and casting

name = input("What is your name? ")
age = int(input("How old are you? "))
print("Hi " + name + ", next year you'll be " + str(age + 1))
  1. input() always gives back a string, even if you type digits.
  2. int() turns "13" into 13 so you can do maths. This is casting.
  3. str() turns 14 back into text so it can join other text.

Year 9 · Physical Computing · Lesson 2 of 5

The maths: From sensor reading to °C

Symbols first, then the words, then the equation. Change the numbers.

Year 9 · Physical Computing · Lesson 2 of 5

The maths: From ADC reading to volts and brightness

Symbols first, then the words, then the equation. Change the numbers.

Year 9 · Physical Computing · Lesson 2 of 5

Quick quiz · 1 of 3

To show change over time, use a…

  1. A Line chart
  2. B Pie chart
  3. C Scatter graph

A. Line chart

A line joins the points in time order, so you see the trend.

Year 9 · Physical Computing · Lesson 2 of 5

Quick quiz · 2 of 3

SELECT FirstName FROM Students WHERE Year = 8; returns…

  1. A Every field of every student
  2. B The number of Year 8 students
  3. C Only the first names of Year 8 students

C. Only the first names of Year 8 students

WHERE keeps the Year 8 records. SELECT keeps only the FirstName field.

Year 9 · Physical Computing · Lesson 2 of 5

Quick quiz · 3 of 3

A face-recognition model works badly on faces unlike its training photos. This is…

  1. A Bias from unrepresentative training data
  2. B A syntax error
  3. C Overflow

A. Bias from unrepresentative training data

The model only learns what it is shown. Missing groups in the data means worse results for those groups.

Year 9 · Physical Computing · Lesson 2 of 5

Exit ticket

Answer on paper before you go. Then check.

  1. Which register holds the address of the next instruction?

    A PCB MDRC ACC

    A. PC The Program Counter points to the next instruction. It goes up by 1 during each fetch.

  2. RAM is volatile. That means…

    A It loses everything when power is offB It is very fastC It can catch fire

    A. It loses everything when power is off Volatile = forgets without power.