Code Playground

A virtual board to test any sample code, in Arduino C++ or Python. Set the knob, light sensor and button before you press Run. The emulator runs your program, then plays it back on the board.

Quick reference: what the emulator understands
Arduino C++Python
pinMode(pin, OUTPUT/INPUT)p = Pin(pin, Pin.OUT / Pin.IN)
digitalWrite(pin, HIGH/LOW)p.on() · p.off() · p.value(1) · p.toggle()
digitalRead(pin)p.value()
analogRead(A0) → 0–1023ADC(0).read() → 0–1023 · read_u16() → 0–65535
analogWrite(10, 0–255)PWM(Pin(10)).duty(0–1023)
delay(ms) · millis()time.sleep(s) · time.sleep_ms(ms) · time.ticks_ms()
Serial.begin(9600) · Serial.print(x) · Serial.println(x, HEX)print(x) · hex(x) · bin(x)
#include <Servo.h> · Servo s; · s.attach(9) · s.write(90)from servo import Servo · s = Servo(9) · s.write(90)
tone(8, 440) · noTone(8)Pin(8, Pin.OUT).on() · .off()
map() · constrain() · random(a, b) · min() · max() · abs()Python built-ins, import random, import math
robot.forward(n) · turnLeft() · turnRight() · obstacleAhead() · obstacleLeft() · obstacleRight() · atGoal() from robot import robot · forward(n) · turn_left() · turn_right() · obstacle_ahead() · obstacle_left() · obstacle_right() · at_goal()

The emulator runs a beginner-friendly subset of Arduino C++: variables, if/else, loops, functions, arrays, #define, Servo and Serial. Advanced C++ (classes, pointers, libraries other than Servo) needs a real board. Each run lasts up to 20 seconds of simulated time.