Welcome to the World of Inputs and Outputs!
Have you ever wondered how a video game knows when you press a button, or how an automatic door knows when to open for you? In this chapter, we are going to explore the exciting journey of how computers receive information from the outside world, what they do with it, and how they show or act out the results!
Don't worry if computing terms seem tricky at first. By looking at real-life examples and fun coding projects, you will become an expert in no time!
The Big Idea: The Input-Process-Output (IPO) Cycle
Every computer system, robot, and program follows a simple three-step cycle called the IPO Cycle:
• 1. Input: Information, data, or signals going into the computer from a user or a sensor.
• 2. Process: The computer's brain (algorithm) thinking, calculating, or following rules using that information.
• 3. Output: The result coming out of the computer, such as a picture, sound, light, or physical movement.
A Real-Life Analogy: Making Toast
Think of a toaster like a computer system:
• Input: You put bread in and push down the lever.
• Process: The timer counts down and the heating elements warm up.
• Output: Delicious, warm, crispy toast pops up!
Key Takeaway: Without an input, a computer has nothing to work with. Without processing, it cannot make decisions. Without an output, we would never see or hear the result!
Various Forms of Input
An input is any data or signal that triggers an action or provides information to a program. Inputs can come directly from a human or from the physical environment.
1. User Inputs (Direct Actions from You!)
These are the ways you give instructions to a computer while playing a game or using a program:
• Key Presses: Pressing the spacebar, arrow keys, or typing letters on a keyboard to control a character or enter text.
• Mouse and Pointer Events: Clicking buttons, dragging items, or moving your mouse across coordinates on the screen (the \(x, y\) position).
• Touchscreen Gestures: Tapping, swiping, or pinching on a tablet or phone screen.
• Text and Number Prompts: Typing an answer when a program asks a question (like the ask [What's your name?] and wait block in Scratch, which puts your typing into the answer block).
• Audio / Voice: Sound captured by a microphone (such as measuring how loud you clap in a game or recording your voice).
2. Sensor Inputs (Physical Computing)
Computers do not just sit on desks; they can be built into smart devices like the BBC micro:bit or Crumble controller. These devices use physical inputs:
• Push Buttons and Switches: Pressing Button A or Button B on a micro:bit, or flicking a switch on a circuit.
• Light Sensors (LDRs): Measuring how bright or dark a room is (used in automatic nightlights).
• Temperature Sensors: Checking how hot or cold the air is.
• Motion Sensors (Accelerometers): Detecting when a device is shaken, tilted, or moved.
• Moisture Sensors: Testing if soil is wet or dry for an automatic plant-watering system.
Did you know? An automatic streetlight does not turn on by magic—it has a tiny light sensor (an input) that detects when the sun goes down!
Key Takeaway: Inputs can be user actions (like clicking or typing) or sensor readings from the world around us (like light, tilt, or temperature).
Various Forms of Output
An output is the action, signal, sound, or display produced by the computer after it finishes processing the instructions.
1. Visual Outputs (Things We Can See)
• On-Screen Graphics: A sprite moving across the screen, changing its costume, growing bigger, or displaying a speech bubble (using say or think blocks).
• Scoreboards and Text: Showing the player's final score or a message on a monitor.
• Single LEDs: Tiny lights turning on, off, or flashing.
• Multi-colour Lights (NeoPixels / Sparkles): Coloured lights changing between red, green, and blue on a physical circuit.
• LED Matrix Displays: A grid of lights, such as the \(5 \times 5\) LED screen on a BBC micro:bit, showing smiley faces, numbers, or scrolling text.
2. Auditory Outputs (Things We Can Hear)
• Speakers and Buzzers: Playing a sound effect (like a "boing" when a character jumps), playing musical notes, sounding a warning beep, or speaking words aloud.
3. Kinetic and Physical Outputs (Things That Move or Shake)
• Motors: Spinning robot wheels to make a rover drive forward.
• Servos: Turning an arm a specific amount, like lifting an automatic car park barrier.
• Vibration / Haptic Feedback: A tiny motor shaking a game controller when your player bumps into a wall.
Key Takeaway: Outputs let computers communicate with the world through sight (screens and LEDs), sound (speakers and buzzers), and movement (motors and servos).
Using Inputs and Outputs in Algorithms and Code
Now let's see how inputs and outputs connect together inside your coding projects!
1. Event-Driven Inputs
In block-based languages like Scratch, programs often wait for an event (an input) to trigger a set of instructions:
• when [space] key pressed \(\implies\) play sound [Laser]
• when this sprite clicked \(\implies\) next costume
• when shaken (on a micro:bit) \(\implies\) display random number
2. Condition-Driven Inputs (Selection)
We can use selection (an if... then... else block) to check the input and decide what output to produce:
• if <key [up arrow] pressed?> then change y by \(10\)
• if <temperature \(> 25\)> then turn motor [ON] (to run a cooling fan!)
3. Storing Inputs in Variables
A variable is a named storage box in computer memory that holds data. When a user provides an input, we often store it in a variable so we can use it later:
• Step 1: The computer asks: "What is your name?" (Input prompt)
• Step 2: The user types: "Maya" (Input data)
• Step 3: The program sets the variable PlayerName to answer (Storing the input)
• Step 4: The sprite says: "Hello Maya!" (Output)
4. Predicting and Testing Outputs (Debugging)
Good computer scientists always test their programs! You should create test inputs to check if the outputs match what you expect:
• Test Input: Press the Right Arrow key.
• Expected Output: Sprite moves \(10\) steps to the right.
• Actual Output: Sprite moves \(10\) steps up. (Uh oh! We found a bug in the code to fix!).
Key Takeaway: Inputs trigger events or check conditions, and storing them in variables helps programs produce the exact outputs we want.
Common Mistakes and Pitfalls to Avoid
Watch out for these common traps that can trip up young programmers!
• Mistake 1: Confusing Monitors with Input Devices.
Fact: A regular computer screen is an output device because it shows images. A touchscreen is special because it acts as both an input device (detecting your touch) and an output device (showing the screen) at the same time!
• Mistake 2: Thinking Computers Act "All by Themselves".
Fact: Automatic devices (like automatic sliding doors or garden sprinklers) don't have human brains. They are running pre-programmed algorithms that wait for specific sensor inputs (motion or moisture) before triggering their outputs.
• Mistake 3: Forgetting the "Process" Step.
Fact: An input cannot turn into an output instantly without an instruction. If you ask a user for two numbers, the computer will not add them together unless your algorithm includes the calculation block!
• Mistake 4: Confusing Storage with Input/Output.
Fact: USB memory sticks and hard drives are used for storage (saving files for later), not for directly sensing the world (inputs) or displaying actions (outputs).
Quick Review: Check Your Knowledge!
Let's see how much you have learned with these quick matching challenges:
Match the Input to the Sensor:
1. Shaking a game controller \(\implies\) Accelerometer / Motion Sensor
2. Checking if the bedroom is dark \(\implies\) Light Sensor (LDR)
3. Typing your secret password \(\implies\) Keyboard (Key Presses)
Match the Output to the Device:
1. Showing a smiley face on a micro:bit \(\implies\) \(5 \times 5\) LED Matrix Screen
2. Making a toy car drive across the carpet \(\implies\) Motor
3. Playing a victory tune when you win \(\implies\) Speaker / Buzzer
Remember the golden rule: Input goes in, the algorithm Processes the data, and the Output comes out!