MicroPython#

The {exec} micropython directive allows uploading and executing Python code on an embedded system running MicroPython.

Generic#

1print("(This line is printed from the preamble.)")
1name = input("What's your name? ")
2print("Hello, %s!" % name)

BBC micro:bit V2#

1from microbit import *
2from time import sleep
3
4display.on()
5for name in dir(Image):
6  if not name[0].isupper() or name.startswith('ALL_'): continue
7  print(name)
8  display.show(getattr(Image, name))
9  sleep(0.5)

Raspberry Pi Pico#

 1from machine import Pin, unique_id
 2from neopixel import NeoPixel
 3from time import sleep
 4
 5if unique_id() in [b'\xdeb4\x10\x9fr\x0f0']:  # RP2040-One
 6  led = NeoPixel(Pin.board.GP16, 1)
 7  for i in range(2 * 256, 2 ** 3 * 2 * 256):
 8    v = i & 255
 9    if (i >> 8) & 1: v = 255 - v
10    led[0] = (v * ((i >> 10) & 1), v * ((i >> 9) & 1), v * ((i >> 11) & 1))
11    led.write()
12    sleep(0.002)
13  led[0] = (0, 0, 0)
14  led.write()
15
16else:  # Generic
17  led = Pin("LED", Pin.OUT)
18  for i in range(20):
19    led.toggle()
20    sleep(0.2)