/********* Minimum value *********/min ()//implementation: #define MIN (a) (a) < (b)? ( A):(B))/********* Maximum Value *********/Max ()//implementation: #define MAX (A, B) ((a) > (c)? ( A):(B))/********* Absolute *********/ABS ()//implementation: #define ABS (x) ((x) >0? ( X):( -X))/********* adjustment to Interval *********///if the value of AMT is less than low, returns low if the Amt is greater than high, otherwise, returns AMT. can be used to normalized values to a rangeconstrain ()//implementation: #define CONSTRAIN (AMT, Low, High) (AMT) < (low)? ( Low):((AMT) > (high)? (high):(Amt )))/********* Mapping *********/LongMapLongXLongIn_min,LongIn_max,LongOut_min,LongOut_max);//map the x between [In_min, In_max] to [Out_min, Out_max]. Parameters: x value to map in_min map before interval In_max map interval out_min map post interval/********* exponential operation *********/DoublePOW (float Base,floatexponent);/********* Square Operation *********/DoublesqrtDoubleX//implementation: #define SQRT (x) ((x) * ( x))/********* Trigonometric Operations *********/floatSinfloatrad);floatCosfloatrad);floatTan (Flaot rad);/********* Random number operation *********/voidRandomseed (unsignedintSeed);//seed: Random seedLongRandomLongHOWBIG);//generate random number, range [0,howbig-1]/******** bit Operation *********/#defineLowbyte (W) ((w) & 0xFF)//Take low byte#defineHighbyte (W) ((W) >> 8)//take high byte#defineBitread (value, Bit) (((value) >> (bit)) & 0x01)//read a bit#defineBitwrite (value, bit, bitvalue) (Bitvalue? BitSet (value, bit): bitclear (value, bit))//write a bit#defineBitSet (value, Bit) ((value) |= (1UL << (bit))//set a bit#defineBitclear (value, Bit) ((value) &= ~ (1UL << (bit)))//empty a bit#defineBit (b) (1 << (b))//generate the appropriate bit
ARDUINO101 Study Notes (eight)--Library of functions