Built-in project · STM32F411 Black Pill

STM32 chaser

The same six-LED sweep on the Black Pill, wired to PA1 through PA6. The whole build, an STM32 Black Pill and 12 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Runs in your browser. Free, and no account needed.

STM32 chaser · STM32F411 Black Pilllive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · STM32F411 Black Pill
// Chaser: a dot sweeping back and forth along six LEDs.
//
// One GPIO per lamp: PA1 to PA6, in order along the Black Pill's left header.
// No shift register, no timer, just six pinMode calls and a loop, the same
// circuit as the ESP32-C3 Knight Rider example, wired to a different board.
//
// The sweep turns round one short of each end, so the two end lamps light
// once a pass and the middle ones twice.

const int LAMPS[] = {PA1, PA2, PA3, PA4, PA5, PA6};
const int COUNT = 6;
const int STEP_MS = 90;

static void show(int lit) {
  for (int i = 0; i < COUNT; i++) {
    digitalWrite(LAMPS[i], i == lit ? HIGH : LOW);
  }
}

void setup() {
  for (int i = 0; i < COUNT; i++) {
    pinMode(LAMPS[i], OUTPUT);
    digitalWrite(LAMPS[i], LOW);
  }
  Serial.begin(115200);
  Serial.println("Mokxi STM32F411: six lamps, one dot");
}

void loop() {
  for (int i = 0; i < COUNT; i++) {
    show(i);
    delay(STEP_MS);
  }
  for (int i = COUNT - 2; i > 0; i--) {
    show(i);
    delay(STEP_MS);
  }
}

Parts list

14 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

13 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • STM32F411 Black Pill pin PA1; Resistor, 220 Ω (1) pin 1
  • STM32F411 Black Pill pin PA2; Resistor, 220 Ω (2) pin 1
  • STM32F411 Black Pill pin PA3; Resistor, 220 Ω (3) pin 1
  • STM32F411 Black Pill pin PA4; Resistor, 220 Ω (4) pin 1
  • STM32F411 Black Pill pin PA5; Resistor, 220 Ω (5) pin 1
  • STM32F411 Black Pill pin PA6; Resistor, 220 Ω (6) pin 1
  • Ground: STM32F411 Black Pill pin GND; LED, red (1) pin C; LED, red (2) pin C; LED, red (3) pin C; LED, red (4) pin C; LED, red (5) pin C; LED, red (6) pin C
  • Resistor, 220 Ω (1) pin 2; LED, red (1) pin A
  • Resistor, 220 Ω (2) pin 2; LED, red (2) pin A
  • Resistor, 220 Ω (3) pin 2; LED, red (3) pin A
  • Resistor, 220 Ω (4) pin 2; LED, red (4) pin A
  • Resistor, 220 Ω (5) pin 2; LED, red (5) pin A
  • Resistor, 220 Ω (6) pin 2; LED, red (6) pin A

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.