About this video
This lesson shows how sensor inputs and outputs are wired together in a block-based programming environment. A light sensor gives a value from 0 to 100, which the lesson connects to a sound block's pitch input. Wiring the intensity to pitch makes the tone change as the room gets lighter or darker, and a loop keeps the behaviour updating in real time.
You'll be able to
- identify inputs and outputs and explain what each one does
- wire a sensor output to an output input in a block-based environment
- explain why a loop is needed to keep a wired behaviour updating
Key words
- Input
- Any sensor that provides data to the brain, such as a light sensor giving a value.
- Output
- A device such as a motor, lamp or speaker that receives numbers telling it how to behave.
- Intensity
- The light sensor's value from 0 to 100 representing how bright the surroundings are.
- Pitch
- The frequency of a tone, which a speaker output uses as one of its controllable features.
- Loop
- A structure that repeats a block of instructions so that wired values keep updating.
Transcript
It's very powerful to understand how our inputs and outputs can communicate with each other, or more specifically, how they can be wired together. Now these two things speak the language of numbers. Our inputs are anything that is providing data to the brain, so any of our sensors.
For example, let's pretend we plugged in a light sensor. Now the light sensor provides a value, and this will depend on the sensor you're using. In the case of a light sensor, it's providing a value between 0 and 100 which represents the intensity of the current light condition in front of the sensor.
Now our outputs are the opposite-- our motor or our lamp or speaker. Outputs we actually provide a number to so they know how to behave. And in the case-- if this was a motor, we would provide it direction and power, but for the speaker, we could provide it multiple outputs, such as pitch, which is the frequency of a tone, and we can also send it volume, and these are the two most important features.
Now the powerful thing to realize is that we could take this intensity value and plug it in to, say, pitch. So as the environment changes-- if we flip the lights on or grab a flashlight-- you will actually hear this change in real time using the speaker. So let's grab an input, for example, our light sensor and an output, for example, the sound block.
And to wire blocks together, you first have to click on the bottom of the block, which will expand this little column here, which will give you access to them, and here are all my inputs and outputs-- inputs on the left, outputs on the right-hand side. So remember, we want to take our light intensity-- and if I scroll down, there is an intensity output here.
And I can click on it and then drag this wire and I will plug it into the pitch or tone frequency input on this sound block. Now there's also volume and other things here. I plugged it into pitch. So now these two blocks are wired together. So to get a dynamic behavior, you need to drop this inside a loop, and then it will continue to update and you should be able to hear the difference.
Video © Khan Academy, used under CC BY-NC-SA. Watch on Khan Academy. Puzzicle is not affiliated with Khan Academy.