Arduino Programming Reference: Variables, Functions & Syntax
Classified in Computers
Written on in
English with a size of 12.76 KB
Variables
Array
int myInts[6];
int myPins[] = {2, 4, 8, 3, 6};
int mySensVals[6] = {2, 4, -8, 3, 2};
char message[6] = "hello";Bool
int LEDpin = 5; // LED on pin 5
int switchPin = 13; // momentary switch on 13, other side connected to ground
bool running = false;
void setup()
{
pinMode(LEDpin, OUTPUT);
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH); // turn on pullup resistor
}
void loop()
{
if (digitalRead(switchPin) == LOW)
{
delay(100); // delay to debounce switch
running = !running; // toggle running variable
digitalWrite(LEDpin, running); // indicate via LED
}
}Char
char myChar = 'A';
char myChar = 65; // both are equivalentDouble
Double precision floating point number. On the Uno and other ATMEGA-based boards, this occupies 4 bytes. That is, the double implementation is exactly the same as the float, with no gain in precision. On the Arduino Due, doubles have 8-byte (64-bit) precision.
Float
float var = val;var - your float variable name
val - the value you assign to that variable
Int
int var = val;var - your int variable name
val - the value you assign to that variable
String
char Str1[15];
char Str2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};
char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};
char Str4[ ] = "arduino";
char Str5[8] = "arduino";
char Str6[15] = "arduino";Void
void setup()
{
// ...
}
void loop()
{
// ...
}Word
word w = 10000;Functions
Digital I/O
Analog I/O
Zero, Due & MKR Family
Advanced I/O
Time
Math
Trigonometry
Characters
- isAlpha()
- isAlphaNumeric()
- isAscii()
- isControl()
- isDigit()
- isGraph()
- isHexadecimalDigit()
- isLowerCase()
- isPrintable()
- isPunct()
- isSpace()
- isUpperCase()
- isWhitespace()
Random Numbers
Bits and Bytes
External Interrupts
Interrupts
Communication
USB
Structures
Constants
- Floating Point Constants
- Integer Constants
- HIGH | LOW
- INPUT | OUTPUT | INPUT_PULLUP
- LED_BUILTIN
- true | false
Conversion
Data Types
- String()
- array
- bool
- boolean
- byte
- char
- double
- float
- int
- long
- short
- string
- unsigned char
- unsigned int
- unsigned long
- void
- word