Arduino Tutorial
Arduino Useful Resources
Selected Reading
- Arduino - Network Communication
- Arduino - Wireless Communication
- Arduino - Tone Library
- Arduino - Stepper Motor
- Arduino - Servo Motor
- Arduino - DC Motor
- Arduino - Connecting Switch
- Arduino - Ultrasonic Sensor
- Arduino - PIR Sensor
- Arduino - Water Detector / Sensor
- Arduino - Temperature Sensor
- Arduino - Humidity Sensor
- Arduino - Keyboard Serial
- Arduino - Mouse Button Control
- Arduino - Keyboard Message
- Arduino - Keyboard Logout
- Arduino - LED Bar Graph
- Arduino - Reading Analog Voltage
- Arduino - Fading LED
- Arduino - Blinking LED
- Arduino - Serial Peripheral Interface
- Arduino - Inter Integrated Circuit
- Arduino - Communication
- Arduino - Interrupts
- Arduino - Random Numbers
- Arduino - Pulse Width Modulation
- Arduino - Due & Zero
- Arduino - Trigonometric Functions
- Arduino - Math Library
- Arduino - Character Functions
- Arduino - Advanced I/O Function
- Arduino - I/O Functions
- Arduino - Arrays
- Arduino - Time
- Arduino - String Object
- Arduino - Strings
- Arduino - Functions
- Arduino - Loops
- Arduino - Control Statements
- Arduino - Operators
- Arduino - Variables & Constants
- Arduino - Data Types
- Arduino - Program Structure
- Arduino - Installation
- Arduino - Board Description
- Arduino - Overview
- Arduino - Home
Arduino Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Arduino - Math Library
Arduino - Math Library
The Arduino Math pbrary (math.h) includes a number of useful mathematical functions for manipulating floating-point numbers.
Library Macros
Following are the macros defined in the header math.h −
Library Functions
The following functions are defined in the header math.h −
Example
The following example shows how to use the most common math.h pbrary functions −
double double__x = 45.45 ; double double__y = 30.20 ; void setup() { Serial.begin(9600); Serial.print("cos num = "); Serial.println (cos (double__x) ); // returns cosine of x Serial.print("absolute value of num = "); Serial.println (fabs (double__x) ); // absolute value of a float Serial.print("floating point modulo = "); Serial.println (fmod (double__x, double__y)); // floating point modulo Serial.print("sine of num = "); Serial.println (sin (double__x) ) ;// returns sine of x Serial.print("square root of num : "); Serial.println ( sqrt (double__x) );// returns square root of x Serial.print("tangent of num : "); Serial.println ( tan (double__x) ); // returns tangent of x Serial.print("exponential value of num : "); Serial.println ( exp (double__x) ); // function returns the exponential value of x. Serial.print("cos num : "); Serial.println (atan (double__x) ); // arc tangent of x Serial.print("tangent of num : "); Serial.println (atan2 (double__y, double__x) );// arc tangent of y/x Serial.print("arc tangent of num : "); Serial.println (log (double__x) ) ; // natural logarithm of x Serial.print("cos num : "); Serial.println ( log10 (double__x)); // logarithm of x to base 10. Serial.print("logarithm of num to base 10 : "); Serial.println (pow (double__x, double__y) );// x to power of y Serial.print("power of num : "); Serial.println (square (double__x)); // square of x } void loop() { }
Result
cos num = 0.10 absolute value of num = 45.45 floating point modulo =15.25 sine of num = 0.99 square root of num : 6.74 tangent of num : 9.67 exponential value of num : ovf cos num : 1.55 tangent of num : 0.59 arc tangent of num : 3.82 cos num : 1.66 logarithm of num to base 10 : inf power of num : 2065.70Advertisements