Skip to Content
Maestro Docs
Sim LabArduino

Writing Arduino code

Sketches and AVR C, the files you can use, libraries that are available, and a starter example.

Two ways to write code

The Code panel next to the circuit has a mode for each way of programming the board. A question can limit which one you may use.

ModeFileWhat it is
Arduino sketchsketch.inoThe normal Arduino language (C++ with setup() and loop()).
AVR Cmain.cPlain C that works with the chip's registers directly (avr-libc).

The editor has syntax colouring and autosaves.

Your first sketch

The starter sketch blinks the built-in LED on pin 13 and prints "on" and "off" to the serial monitor. This is the idea:

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(13, HIGH);
  Serial.println("on");
  delay(500);
  digitalWrite(13, LOW);
  Serial.println("off");
  delay(500);
}

Wire an LED (with a resistor) from pin 13 to ground, press Upload, and it blinks.

Files

  • Most programs are a single file (sketch.ino or main.c). A program can have up to 8 files, and the whole program can be at most 64 KB.
  • File names use letters, digits, _ and -, then a short extension, for example helpers.h.
  • Sketches can use .ino, .cpp, .c, .h and .S. AVR C can use .c, .h and .S.
  • If you have several .ino tabs, they are joined together the way the Arduino IDE does it. Function prototypes are made for you, so you can call a function that is defined below loop().

Libraries you can include

These are built in. You can #include them without installing anything.

LibraryFor
ServoServo motors
LiquidCrystalParallel 16×2 LCD
LiquidCrystal_I2C and LiquidCrystal_PCF8574I2C LCD (lcd.init(); lcd.backlight(); style sketches build)
Wire, SPI, SoftwareSerialThey compile, but there is no device to talk to for SPI and SoftwareSerial
EEPROMThe chip's 1 KB EEPROM
SerialBuilt into the core

Language notes

  • The board uses the standard Arduino AVR core. C++ exceptions are not available.
  • Errors point to your own file and line, for example sketch.ino:3.