About this video
When blocks are wired together, their value ranges can clash. This video shows a light sensor (0 to 100) feeding a pitch input that expects 0 to 1,000, which would only use a tenth of the range. The fix is a math block between the two, which can add, subtract, multiply, divide, take an absolute value or a square root on input A using a value B, so the output lands in the right range.
You'll be able to
- recognise a range mismatch when two blocks are connected.
- choose a math block operation and value B to rescale a number to a target range.
- predict how much of an input range a mismatched value will actually use.
Key words
- Range mismatch
- A problem that occurs when one block sends values in a different range from what the next block expects.
- Math block
- A block that takes inputs A and B and applies an operation, such as multiply or divide, to produce an output.
- Input
- A socket on a block that receives a value from another block or from a number you type in.
- Scaling
- Multiplying or dividing a value by a fixed amount so it fits a different range.
- Operation
- The arithmetic action the math block performs on A and B, such as addition or division.
Transcript
When we wire blocks together, we will often run into a problem, and it's a range mismatch. For example, if we had the light intensity value being plugged into the pitch input of the speaker, let's see what would happen. Our light intensity value will send it a number between 0 and 100.
However, the pitch input varies from 0 to 1,000, because it is a different measure. So these are all the different tones. If we think of it as a piano, this is the whole width of the piano. So if we'd plug these in directly, we actually would only hit 10% of all the values here, and this means this number would need to be scaled by some amount.
And that is when we can use our math block to help us. The math block is very simple. It takes two inputs, A and B, which you can plug into just like I've shown you, and it spits out an output. So what you could do is multiply things together, or scale a number, or say, take whatever A is and add 5 to it and spit that as your output.
So in this case, I have a light sensor and a sound sensor, and instead of plugging them together, I'm going to drop a math block in between them. And now provide the light intensity value to A-- that's the first input-- and I'm not going to give it another input B because I just want to either add, multiply, or do something to this number, A.
And I'll take the result of whatever operation we come up with and plug it into tone frequency. So in the math block, just to be clear, the operations are addition, subtraction, multiplication, division, absolute value, and square root, so you should select the correct operation here and fill in B.
So let's say we wanted to divide it by 5. I would put 5 in the box for B. So if I provided the number 50, it would be divided by 5, which is 10, and 10 would spit out the other end. So fix this so that after the math block, the value ranges from 0 to 1,000.
Video © Khan Academy, used under CC BY-NC-SA. Watch on Khan Academy. Puzzicle is not affiliated with Khan Academy.