Math
Math
Numbers are everywhere in programming.
Programs use numbers to:
- Count points
- Measure temperature
- Control LEDs
- Move servos
- Measure distance
- Create random events
The Math category gives your program the ability to calculate, compare, transform, and control values.
Think of Math as the calculator inside your robot.
What Is Math?
Math blocks allow a program to work with numbers.
Examples:
5 + 3 = 8
10 - 2 = 8
4 × 2 = 8
16 ÷ 2 = 8
Math helps programs transform numbers into useful information.
Think of Math as the calculator inside your project.
Math Category
[INSERT CATEGORY IMAGE HERE: Math]
Figure 4.1 – Blocks available in the Math category.
The category can be organized into:
NUMBERS
↓
CALCULATE
↓
RANDOM
↓
LIMIT
↓
MAP
Math Block Quick Reference
| Block | Purpose | Main Idea |
|---|---|---|
| Number | Create a value | Starting number |
| Add (+) | Add values | Bigger number |
| Subtract (-) | Take away | Smaller number |
| Multiply (×) | Scale values | Repeat groups |
| Divide (÷) | Split values | Share equally |
| Random Integer | Random whole number | Surprise value |
| Random Decimal | Random decimal value | More precise randomness |
| Round | Simplify decimals | Cleaner number |
| Max | Largest value | Biggest wins |
| Min | Smallest value | Smallest wins |
| Constrain | Set limits | Stay in range |
| Map | Change ranges | Scale values |
| Convert to Integer | Remove decimals | Whole number |
| Constants | π and e | Special math values |
| Variable Math | Change stored values | Counters and scores |
Numbers
Everything starts with a number.
Examples:
0
10
50
100
Numbers can be connected to almost every category.
Examples:
Number → Math
Number → Logic
Number → Variables
Number → Servo
Number → Sensor Threshold
Basic Calculations
[INSERT BLOCK IMAGE HERE: Arithmetic Operations]
The most important Math blocks are:
| Operation | Example |
|---|---|
| Add | 5 + 3 |
| Subtract | 10 - 2 |
| Multiply | 4 × 2 |
| Divide | 12 ÷ 3 |
Concept
Number
+
Number
↓
Result
Example
Temperature
+
5
↓
New Temperature
Updating Values
[INSERT BLOCK IMAGE HERE: Variable Math]
Sometimes a value changes over time.
Example:
score += 1
Meaning:
Current Score
+
1
↓
New Score
Useful for:
Counters
Scores
Timers
Tracking events
Random Numbers
[INSERT BLOCK IMAGE HERE: Random Integer]
Programs can create random values.
Possible results:
12
57
98
Uses
Games
Random challenges
Simulations
Surprise effects
Rounding Numbers
[INSERT BLOCK IMAGE HERE: Round]
Sometimes numbers have many decimal places.
Example:
4.83
↓
Round
↓
5
round(4.83)Maximum and Minimum
Programs often compare values.
Maximum
max(10,20)
Result:
20
Minimum
min(10,20)
Result:
10
Easy Memory Tip
MAX = Largest
MIN = Smallest
Constrain
[INSERT BLOCK IMAGE HERE: Constrain]
Constrain keeps values inside limits.
Example:
Range:
0 → 100
Value:
120
Result:
100
Concept
Value
↓
Limit
↓
Allowed Value
Constrain sets boundaries.
Map
[INSERT BLOCK IMAGE HERE: Map]
Map converts a value from one range into another.
Example
Sensor Range:
0 → 100
Servo Range:
0 → 180
Concept
Old Range
↓
Map
↓
New Range
math_map(50,1,100,1,180)Map changes scale.
Math and Sensors
Math becomes powerful when combined with sensors.
Example:
Temperature Sensor
↓
Reading
↓
Math
↓
Display
Another example:
Distance Sensor
↓
Map
↓
Servo Position
Math and Logic
Math and Logic often work together.
Math:
5 + 3
↓
8
Logic:
8 > 5
↓
TRUE
Programs often follow:
Sensor
↓
Math
↓
Logic
↓
Action
Soccer Score Counter
Concept:
Goal
↓
Score + 1
↓
LCD
Skills:
Variables
Addition
Counting
Temperature Converter
Concept:
Temperature Sensor
↓
Math
↓
New Value
↓
LCD
Skills:
Sensors
Arithmetic
Displays
LED Brightness Controller
Concept:
Sensor
↓
Map
↓
LED Brightness
Skills:
Mapping
Sensor Values
Outputs
Distance Controlled Servo
Concept:
Ultrasonic Sensor
↓
Distance
↓
Map
↓
Servo Position
Skills:
Sensors
Mapping
Servos
Quick Guide for Students
Need a calculation?
Use:
+ - × ÷
Need a random value?
Use:
Random
Need a clean whole number?
Use:
Round
Need the largest value?
Use:
Max
Need the smallest value?
Use:
Min
Need limits?
Use:
Constrain
Need to convert one range into another?
Use:
Map
Quick Reference
| Family | Main Idea |
|---|---|
| Number | Create a value |
| Arithmetic | Calculate |
| Variable Math | Update values |
| Random | Generate values |
| Round | Simplify numbers |
| Max | Largest value |
| Min | Smallest value |
| Constrain | Keep values within limits |
| Map | Change ranges |
Summary
In this lesson, you learned how Math helps programs work with numbers.
You explored:
Numbers
Addition
Subtraction
Multiplication
Division
Variables
Random Numbers
Rounding
Maximum and Minimum
Constrain
Map
Math helps transform raw numbers into useful information that can control displays, sensors, motors, LEDs, and robots.
Key Takeaway
Math is the calculator inside your program. It helps turn numbers into useful information that can control sensors, displays, LEDs, servos, and entire robotics projects.
