Standard Arduino functions, constants and types (from ArduinoCore-API). More...
#include <stdint.h>#include <stdbool.h>Go to the source code of this file.
Macros | |
| #define | PI 3.1415926535897932384626433832795 |
| π, 3.14159... | |
| #define | HALF_PI 1.5707963267948966192313216916398 |
| π / 2. | |
| #define | TWO_PI 6.283185307179586476925286766559 |
| 2π. | |
| #define | DEG_TO_RAD 0.017453292519943295769236907684886 |
| Radians per degree, π / 180. | |
| #define | RAD_TO_DEG 57.295779513082320876798154814105 |
| Degrees per radian, 180 / π. | |
| #define | EULER 2.718281828459045235360287471352 |
| e, 2.71828... | |
| #define | constrain(amt, low, high) |
| Limits a value to a range: low if below it, high if above it. | |
| #define | radians(deg) |
| Converts degrees to radians. | |
| #define | degrees(rad) |
| Converts radians to degrees. | |
| #define | sq(x) |
| The square of a number, x * x. | |
| #define | lowByte(w) |
| The low (rightmost) byte of a value. | |
| #define | highByte(w) |
| The second-lowest byte of a value (bits 8-15). | |
| #define | bitRead(value, bit) |
| Reads bit number bit (0 = rightmost) of a value: 0 or 1. | |
| #define | bitSet(value, bit) |
| Sets bit number bit of a variable to 1. | |
| #define | bitClear(value, bit) |
| Sets bit number bit of a variable to 0. | |
| #define | bitToggle(value, bit) |
| Flips bit number bit of a variable. | |
| #define | bitWrite(value, bit, bitvalue) |
| Sets bit number bit of a variable to bitvalue (0 or 1). | |
| #define | bit(b) |
| The value of bit number b: 1, 2, 4, 8, ... | |
| #define | word(...) |
| Same as makeWord(). | |
Typedefs | |
| typedef void(* | voidFuncPtr) (void) |
| Function with no arguments and no return value, as used by attachInterrupt(). | |
| typedef void(* | voidFuncPtrParam) (void *) |
| Function taking a void*, as used by attachInterruptParam(). | |
| typedef bool | boolean |
| Old name for bool. | |
| typedef uint8_t | byte |
| 8-bit unsigned number, 0-255 (uint8_t). | |
| typedef uint16_t | word |
| 16-bit unsigned number, 0-65535 (uint16_t). On an Uno int is 16 bits too, but on Phyduino boards int is 32 bits. | |
| typedef uint8_t | pin_size_t |
| Type for Arduino pin numbers (uint8_t). | |
Enumerations | |
| enum | PinStatus { LOW = 0 , HIGH = 1 , CHANGE = 2 , FALLING = 3 , RISING = 4 } |
| Pin levels for digitalWrite() and digitalRead(), and interrupt modes for attachInterrupt(). More... | |
| enum | PinMode { INPUT = 0x0 , OUTPUT = 0x1 , INPUT_PULLUP = 0x2 , INPUT_PULLDOWN = 0x3 , OUTPUT_OPENDRAIN = 0x4 } |
| Pin modes for pinMode(). More... | |
| enum | BitOrder { LSBFIRST = 0 , MSBFIRST = 1 } |
| Bit order for shiftOut(), shiftIn() and SPISettings. More... | |
Functions | |
| void | yield (void) |
| Called while delay() or USB Serial is waiting. | |
| void | init (void) |
| Core start-up, before setup(): sets the CPU speed (Tools > CPU Speed), the ADC, USB and the inter-core FIFO. | |
| void | initVariant (void) |
| Board start-up, after init(): the on-board ADC and the USB-PD controller. | |
| void | pinMode (pin_size_t pinNumber, PinMode pinMode) |
| Sets a pin as an input or an output. | |
| void | digitalWrite (pin_size_t pinNumber, PinStatus status) |
| Sets an output pin HIGH (3.3 V) or LOW (0 V). | |
| PinStatus | digitalRead (pin_size_t pinNumber) |
| Reads the level on a pin. | |
| int | analogRead (pin_size_t pinNumber) |
| Reads the voltage on an analog pin. | |
| void | analogReference (uint8_t mode) |
| Does nothing: the references are fixed on Phyduino boards. | |
| void | analogWrite (pin_size_t pinNumber, int value) |
| Outputs a PWM signal: a square wave whose duty cycle sets the average voltage. | |
| unsigned long | millis (void) |
| Milliseconds since the board started. | |
| unsigned long | micros (void) |
| Microseconds since the board started, with 1 µs resolution (4 µs on an Uno). | |
| void | delay (unsigned long) |
| Waits a number of milliseconds. | |
| void | delayMicroseconds (unsigned int us) |
| Waits a number of microseconds, exactly, by busy-waiting. | |
| unsigned long | pulseIn (pin_size_t pin, uint8_t state, unsigned long timeout) |
| Measures how long a pulse on a pin lasts. | |
| unsigned long | pulseInLong (pin_size_t pin, uint8_t state, unsigned long timeout) |
| Same as pulseIn(); kept for Arduino compatibility. | |
| void | shiftOut (pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val) |
| Sends a byte one bit at a time, pulsing the clock pin after each bit. | |
| uint8_t | shiftIn (pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder) |
| Reads a byte one bit at a time, pulsing the clock pin for each bit. | |
| void | attachInterrupt (pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode) |
| Calls a function when the level on a pin changes. | |
| void | attachInterruptParam (pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void *param) |
| Same as attachInterrupt(), but the function is called with param. | |
| void | detachInterrupt (pin_size_t interruptNumber) |
| Stops calling the function attached to a pin. | |
| void | setup (void) |
| Written by the sketch: runs once after reset, on core 0. | |
| void | loop (void) |
| Written by the sketch: runs over and over after setup(), on core 0. | |
| template<class T, class L> | |
| auto | min (const T &a, const L &b) -> decltype((b< a) ? b :a) |
| The smaller of two values. | |
| template<class T, class L> | |
| auto | max (const T &a, const L &b) -> decltype((b< a) ? b :a) |
| The larger of two values. | |
| uint16_t | makeWord (uint16_t w) |
| Returns w as a 16-bit word. | |
| uint16_t | makeWord (byte h, byte l) |
| Joins two bytes into a 16-bit word. | |
| void | tone (uint8_t _pin, unsigned int frequency, unsigned long duration=0) |
| Plays a square wave (50 % duty) on a pin, for a buzzer or speaker. | |
| void | noTone (uint8_t _pin) |
| Stops the tone, if one is playing on this pin. | |
| long | random (long) |
| Pseudo-random number from 0 up to, but not including, the argument. | |
| long | random (long, long) |
| Pseudo-random number from the first argument up to, but not including, the second. | |
| void | randomSeed (unsigned long) |
| Starts the random sequence at a new point. | |
| long | map (long, long, long, long, long) |
| Re-maps a number from one range to another, e.g. 0-1023 to 0-255. | |
Standard Arduino functions, constants and types (from ArduinoCore-API).
Included by Arduino.h, so sketches never include it themselves. The functions are grouped by topic under Topics. See the Arduino language reference for the general behaviour; the notes here give what is different on Phyduino boards.