基本ライブラリ
デジタルIO
アナログIO
拡張IO
時間
数学
三角関数
乱数
ビットバイト操作
割り込み
シリアル通信
標準ライブラリ
Ethernet
サーボモーター
ステッピングモーター
キャラクタ液晶表示
SPI通信
I2C通信(Wire)
SD
SD(File操作)
周期処理(MsTimer2)
時計(RTC)
PPG(パルス生成)
WiFiEsp
ICS(シリアルサーボ)
FreeRTOS Tips
数学
大小比較や、各種演算をするためのライブラリです。
min
- 概要
 - 2つの値を比較して小さいほうを返します。
 - 文法
 - min(x, y)
 - パラメータ
 - x: 1つ目の値
y: 2つ目の値 - 戻り値
 - 小さい方の値
 
max
- 概要
 - 2つの値を比較して大きいほうを返します。
 - 文法
 - max(x, y)
 - パラメータ
 - x: 1つ目の値
y: 2つ目の値 - 戻り値
 - 大きい方の値
 
abs
- 概要
 - 絶対値を返します。
 - 文法
 - abs(x)
 - パラメータ
 - x: 変換する値
 - 戻り値
 - xが0以上ならそのままx。xが0未満なら-x。
 
constrain
- 概要
 - 範囲内の数値を返します。
 - 文法
 - constrain(x, a, b)
 - パラメータ
 - x: 任意の値
a: 下限値
b: 上限値 - 戻り値
 - xがaとbの間ならx。xがaより下ならa。xがbより上ならb。
 
map
- 概要
 - ある範囲内にある値を、ある範囲内に置き換えます。例えば0~10の範囲で値が5のとき、0~100の範囲に置き換えると50になります。
 - 文法
 - map(value, fromLow, fromHigh, toLow, toHigh)
 - パラメータ
 - value: 任意の値
fromLow: 元の下限値
fromHigh: 元の上限値
toLow: 置き換え後の下限値
toHigh: 置き換え後の上限値 - 戻り値
 - 置き換え後の値
 
pow
- 概要
 - 指数演算します
 - 文法
 - pow(base, exponent)
 - パラメータ
 - base: 任意の値(float)
exponent: 指数値(float) - 戻り値
 - 演算値(double)
 
sqrt
- 概要
 - 平方根を求めます。
 - 文法
 - sqrt(x)
 - パラメータ
 - x: 任意の値
 - 戻り値
 - 演算値(double)
 
サンプルプログラム
constrainとpowを使ったサンプル。
#include <Arduino.h>
void setup(){
    Serial.begin(9600);
}
 
void loop(){
    Serial.println("Calculate the area of a circle ");
    Serial.println("Input value 0-9");
    while(!Serial.available());
     
    int d = Serial.read();
     
    d = constrain(d - 0x30, 0, 9); //convert from ASCII to numeric, and remove error value
    Serial.print(d);
    Serial.print(" x ");
    Serial.print(d);
    Serial.print(" x 3.14 = ");
 
    Serial.println(pow(d, 2) * PI);
}