Lesson 78: Using abs() Math Function
Learn how abs() returns absolute value and helps compare distance/error without sign confusion.
Lesson Template
Use map(), constrain(), and rounding for sensor logic.
This lesson introduces the core ideas behind Math Functions.
int pwm = map(sensor, 0, 4095, 0, 255);
pwm = constrain(pwm, 0, 255);Learn how abs() returns absolute value and helps compare distance/error without sign confusion.
Learn how constrain() keeps values inside min/max limits for safer sensor and output logic.
Learn how map() scales values between ranges for sensor conversion and output control.
Learn how max() compares two values and returns the larger value for robust decision logic.
Learn how min() compares two values and returns the smaller value for protective control rules.
Learn how pow() raises a base value to an exponent for scaling and formula-based calculations.
Learn how sq() squares values quickly and how it compares with pow(x, 2).
Learn how sqrt() finds square roots for distance formulas and math-driven control calculations.
Learn how cos() generates periodic values from angles for wave-style and cyclic control behavior.
Learn how sin() generates smooth periodic values from angles for wave-style output and cyclic motion logic.
Learn how tan() represents sine/cosine ratio, where its range can grow quickly, and when to use it safely.
Learn how random() generates pseudo-random values, define safe ranges, and improve variability with randomSeed().
Learn how randomSeed() sets generator start state, improves variation after reset, and works with random().