This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:programming_fundamentals_rtu:libraries [2018/02/19 12:19] – Agrisnik | en:iot-open:programming_fundamentals_rtu:libraries [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Libraries ====== | ====== Libraries ====== | ||
| - | ... | + | The opportunities of using Arduino can be extended by using additional libraries. Arduino IDE already contains many libraries that extend the functionality of the sketch in cases of working with hardware or manipulating with data. These libraries can be added to the sketch using //# |
| - | ===== Math library ===== | + | As the example, //Math.h// library is viewed. The use of other libraries, like //Servo.h, LiquidCrystal.h, |
| + | |||
| + | |||
| + | ===== The Math library ===== | ||
| The //Math// library extends the functionality of code in terms of mathematics and is called //math.h//. This header file declares basic mathematics constants and functions. Before starting using it, it must be included in the code at the very beginning in the following way: | The //Math// library extends the functionality of code in terms of mathematics and is called //math.h//. This header file declares basic mathematics constants and functions. Before starting using it, it must be included in the code at the very beginning in the following way: | ||
| Line 11: | Line 14: | ||
| The //Math// library includes multiple functions for manipulating floating point numbers, like //cos, sin, tan, exp, log, log10, pow, square,// etc. The full documentation of the library and functions it includes, can be found in the | The //Math// library includes multiple functions for manipulating floating point numbers, like //cos, sin, tan, exp, log, log10, pow, square,// etc. The full documentation of the library and functions it includes, can be found in the | ||
| - | The following example shows, how the | + | The following example shows, how the //Math.h// library is used in the sketch: |
| + | <code c> | ||
| + | #include < | ||
| + | |||
| + | const double pi = 3.14; | ||
| + | double x = 3.0; | ||
| + | double y = 4.0; | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(9600); | ||
| + | Serial.println(" | ||
| + | Serial.print(cos(pi)); | ||
| + | |||
| + | Serial.println(" | ||
| + | Serial.print(sin(pi)); | ||
| + | |||
| + | Serial.println(" | ||
| + | Serial.print(pow(3, | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | In the given example, three mathematical functions are used - cosine (//cos//), sine (//sin//) and raising to the power (//pow//). The results are printed out to the Serial monitor. In this case functions are used in the //setup// part, so that they are executed only once on initialization. | ||
| - | ===== Random library ===== | ||
| - | Servo library Tone library Display libraries | ||
| - | The use of other libraries, like //Servo.h, LiquidCrystal.h, | ||