Lesson Template

Math Functions

Use map(), constrain(), and rounding for sensor logic.

Progress

5% completed

Lesson Overview

This lesson introduces the core ideas behind Math Functions.

  • map()
  • constrain()
  • min/max

Example Code

int pwm = map(sensor, 0, 4095, 0, 255);
pwm = constrain(pwm, 0, 255);

Lessons in This Section

Lesson 78: Using abs() Math Function

Learn how abs() returns absolute value and helps compare distance/error without sign confusion.

Open Lesson

Lesson 79: Using constrain() Function

Learn how constrain() keeps values inside min/max limits for safer sensor and output logic.

Open Lesson

Lesson 80: Using map() Function

Learn how map() scales values between ranges for sensor conversion and output control.

Open Lesson

Lesson 81: Using max() Function

Learn how max() compares two values and returns the larger value for robust decision logic.

Open Lesson

Lesson 82: Using min() Function

Learn how min() compares two values and returns the smaller value for protective control rules.

Open Lesson

Lesson 83: Using pow() Function

Learn how pow() raises a base value to an exponent for scaling and formula-based calculations.

Open Lesson

Lesson 84: Using sq() Function

Learn how sq() squares values quickly and how it compares with pow(x, 2).

Open Lesson

Lesson 85: Using sqrt() Function

Learn how sqrt() finds square roots for distance formulas and math-driven control calculations.

Open Lesson

Lesson 86: Using cos() Function

Learn how cos() generates periodic values from angles for wave-style and cyclic control behavior.

Open Lesson

Lesson 87: Using sin() Function

Learn how sin() generates smooth periodic values from angles for wave-style output and cyclic motion logic.

Open Lesson

Lesson 88: Using tan() Function

Learn how tan() represents sine/cosine ratio, where its range can grow quickly, and when to use it safely.

Open Lesson

Lesson 89: Using random() Function

Learn how random() generates pseudo-random values, define safe ranges, and improve variability with randomSeed().

Open Lesson

Lesson 90: Using randomSeed() Function

Learn how randomSeed() sets generator start state, improves variation after reset, and works with random().

Open Lesson