UB32 Reference: the Arduino C the simulator runs
The Uno Breadboard Simulator (UB32, version 0.3.2) runs a subset of the
Arduino language: C with the Arduino functions. This page lists every command it runs,
grouped as in the Arduino language reference. A sketch that uses only these commands
builds and runs in the simulator and on a real Uno. See the
UB32 Help page for how to use the simulator.
Back to the simulator.
void setup() { } | runs once when the Uno starts |
void loop() { } | runs again and again after setup() |
int add(int a, int b) { } | your own functions, with return |
#define LED 13 | a name for a value (no parameters) |
#include <...> | ignored; no libraries are loaded |
// and /* */ | comments |
if (x) { } else { } | choose |
for (int i = 0; i < 5; i++) { } | count |
while (x) { } | repeat while true |
do { } while (x); | repeat at least once |
switch (x) { case 1: break; default: } | choose by value |
break; continue; return x; | leave a loop, skip, return |
bool boolean | true or false |
char byte | 8 bits |
int short | 16 bits, as on the Uno |
long | 32 bits |
unsigned int, unsigned long | no negative values |
uint8_t int8_t uint16_t int16_t | fixed sizes |
uint32_t int32_t word size_t | fixed sizes |
float double | decimal numbers |
const static volatile | qualifiers |
int a[5] = {1, 2}; | arrays |
HIGH LOW | pin levels, 1 and 0 |
INPUT OUTPUT INPUT_PULLUP | pin modes |
LED_BUILTIN | pin 13 |
A0 to A5 | analog pins (14 to 19) |
true false | bool values |
DEC HEX BIN OCT | number formats for Serial.print |
PI HALF_PI TWO_PI | circle constants |
DEG_TO_RAD RAD_TO_DEG | angle conversion |
= + - * / % | assign and arithmetic |
== != < > <= >= | compare |
&& || ! | logic |
& | ^ ~ << >> | bits |
++ -- += -= *= /= %= | compound |
&= |= ^= <<= >>= | compound bits |
x ? a : b | choose a value (numbers only) |
pinMode(pin, mode) | INPUT, OUTPUT, or INPUT_PULLUP |
digitalWrite(pin, value) | HIGH or LOW |
digitalRead(pin) | returns HIGH or LOW |
analogRead(pin) | A0 to A5, returns 0 to 1023 |
analogWrite(pin, value) | PWM 0 to 255 (pins 3, 5, 6, 9, 10, 11) |
delay(ms) | wait in milliseconds |
delayMicroseconds(us) | wait in microseconds |
millis() | milliseconds since the start |
micros() | microseconds since the start |
Serial.begin(9600) | start the Serial Monitor |
Serial.print(x) Serial.print(x, HEX) | print a value or text |
Serial.println(x) | print, then a new line |
Serial.write(b) | send one byte |
Serial.available() Serial.read() | return 0 and -1 (no input) |
Serial.println("a:" ...) | name:value pairs draw the Plotter |
map(x, inLow, inHigh, outLow, outHigh) | rescale a value |
constrain(x, low, high) | keep x in a range |
min(a, b) max(a, b) abs(x) | smaller, larger, size |
sq(x) sqrt(x) pow(x, y) | square, square root, power |
sin(x) cos(x) tan(x) | angles in radians |
random(max) random(min, max) | a whole number below max |
randomSeed(n) | start a new random sequence |
bit(n) _BV(n) | the value of bit n |
bitRead(x, n) | bit n of x |
lowByte(x) highByte(x) | the low or high 8 bits |
tone(pin, frequency) | a square wave on the buzzer |
tone(pin, frequency, ms) | for a time |
noTone(pin) | stop the sound |
DDRB PORTB PINB | pins 8 to 13 |
DDRC PORTC PINC | pins A0 to A5 |
DDRD PORTD PIND | pins 0 to 7 |
PORTB |= _BV(PB5); | bit names PB5, DDB5, PINB5 are 0 to 7 |
String, char arrays of text | text only inside Serial.print |
classes, structs, templates, pointers | not in this subset |
libraries (#include) | Servo, Wire, SPI, and others |
attachInterrupt(), Serial input | no interrupts or typing in |
- An int is 16 bits, as on the Uno: it holds −32768 to 32767, and a larger value
wraps around when it is stored. Use long for larger numbers.
- Text is allowed only inside Serial.print, Serial.println, and Serial.write.
- Build checks the spelling of the code (syntax). Upload runs the compiler checks:
setup() and loop() exist, every name is declared, and each function gets the right
number of values.
- Timing is close to the Uno but not exact.
- The full Arduino language reference is at
docs.arduino.cc.