From 6eed3d7f7c9b2404a80462c1100309834186671c Mon Sep 17 00:00:00 2001 From: "M. ASWADI" Date: Sun, 15 Nov 2026 21:33:21 +0700 Subject: [PATCH] docs: add LED letter tutorial --- docs/tutorials/draw-any-letter-with-leds.mdx | 273 +++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 docs/tutorials/draw-any-letter-with-leds.mdx diff --git a/docs/tutorials/draw-any-letter-with-leds.mdx b/docs/tutorials/draw-any-letter-with-leds.mdx new file mode 100644 index 00000000..3dd31ccc --- /dev/null +++ b/docs/tutorials/draw-any-letter-with-leds.mdx @@ -0,0 +1,273 @@ +--- +title: Draw Any Letter with LEDs +description: >- + Build a schematic-first LED letter display by converting a bitmap letter into + individual LEDs, resistors, and power rails in tscircuit. +--- + +import CircuitPreview from "@site/src/components/CircuitPreview" + +## Overview + +This tutorial shows how to draw a letter with ordinary LEDs. We will use a +small 5 by 7 bitmap font, turn each `1` into an LED, and give every LED its own +current-limiting resistor. The final circuit is intentionally simple: one rail +drives the lit pixels through resistors, and every LED returns to ground. + +You can change the letter by replacing the bitmap rows. The same pattern works +for initials, labels, badge art, or a front-panel indicator where the schematic +should clearly show which LEDs are installed. + +## Final circuit + + + row.split("").flatMap((cell, colIndex) => + cell === "1" ? [{ row: rowIndex, col: colIndex }] : [] + ) + ) +} + +export default () => { + const pixels = getLitPixels(letterA) + + return ( + + + + {pixels.map(({ row, col }) => { + const suffix = row + "" + col + return ( + + + + .pin1"} /> + .pin2"} to={".D" + suffix + " > .anode"} /> + .cathode"} to={"net.GND"} /> + + ) + })} + + ) +} +`} /> + +## Step 1: Define the letter + +Use strings to make the shape readable. Each row must have the same number of +characters. A `1` means "place an LED here" and a `0` means "leave this spot +empty." + +```tsx +const letterA = [ + "01110", + "10001", + "10001", + "11111", + "10001", + "10001", + "10001", +] +``` + +Here are three more 5 by 7 letters you can swap in: + +```tsx +const letterT = [ + "11111", + "00100", + "00100", + "00100", + "00100", + "00100", + "00100", +] + +const letterS = [ + "01111", + "10000", + "10000", + "01110", + "00001", + "00001", + "11110", +] + +const letterC = [ + "01111", + "10000", + "10000", + "10000", + "10000", + "10000", + "01111", +] +``` + +## Step 2: Convert the bitmap into pixels + +The helper below returns only the cells that should be populated. Keeping the +empty cells out of the schematic makes the circuit smaller and easier to review. + + + row.split("").flatMap((cell, colIndex) => + cell === "1" ? [{ row: rowIndex, col: colIndex }] : [] + ) + ) +} + +export default () => { + const pixels = getLitPixels(letterT) + + return ( + + {pixels.map(({ row, col }) => ( + + ))} + + ) +} +`} /> + +## Step 3: Add one resistor per LED + +Do not share a single resistor across a whole letter unless you have a driver +that controls current per segment. Separate resistors keep brightness more even +when the letter has rows with different LED counts. + +For a 5 V rail, a red LED around 2 V, and a target current near 9 mA: + +```text +R = (5 V - 2 V) / 0.009 A = 333 ohms +``` + +A standard `330` ohm resistor is a practical starting value. + + ( + + + + + + + + + +) +`} /> + +## Step 4: Generate the letter circuit + +Now combine the bitmap, LED, resistor, and traces. The generated component names +include row and column numbers, so `D34` means row 3, column 4. + + + row.split("").flatMap((cell, colIndex) => + cell === "1" ? [{ row: rowIndex, col: colIndex }] : [] + ) + ) +} + +export default () => { + const pixels = getLitPixels(letterC) + + return ( + + + + {pixels.map(({ row, col }) => { + const suffix = row + "" + col + return ( + + + + .pin1"} /> + .pin2"} to={".D" + suffix + " > .anode"} /> + .cathode"} to="net.GND" /> + + ) + })} + + ) +} +`} /> + +## Review checklist + +Before turning the schematic into a PCB or panel graphic, check the letter +against this list: + +- Every lit pixel has exactly one LED and one resistor. +- All LED anodes are fed through resistors, not directly from the rail. +- All LED cathodes return to ground. +- The row strings all have the same width. +- Component names remain stable after you change letters. +- If the display will be battery powered, increase the resistor value or scan + the LEDs with a driver instead of leaving every LED on continuously.