mohan-bee/disco
This code models a physical circuit board with two IC chips (a 74HC4017 decade counter and a 74HC161 shift register) connected to ten LEDs and resistors arranged in a circular layout with traces routing outputs and power connections.
- Version
- 0.0.1
- License
- unset
- Stars
- 0
index.tsx
PCB
Schematic
import React from "react"
export default Compoo = () => {
const cd4017Outputs = [
"pin3", "pin2", "pin4", "pin7", "pin10",
"pin1", "pin5", "pin6", "pin9", "pin11"
];
return (
<board width="50mm" height="60mm">
<net name="VCC_5V" isPowerNet={true} />
<net name="GND" isGroundNet={true} />
<chip
name="U1"
footprint="soic8"
pcbX={-10}
pcbY={-10}
pinLabels={{
pin1: "GND", pin2: "TRIG", pin3: "OUT", pin4: "RESET",
pin5: "CTRL", pin6: "THR", pin7: "DIS", pin8: "VCC"
}}
/>
<chip
name="U2"
footprint="soic16"
pcbX={10}
pcbY={-10}
pinLabels={{
pin8: "GND", pin13: "EN", pin14: "CLK", pin15: "RST", pin16: "VCC"
}}
/>
<trace from=".U1 > .VCC" to="net.VCC_5V" />
<trace from=".U1 > .GND" to="net.GND" />
<trace from=".U2 > .VCC" to="net.VCC_5V" />
<trace from=".U2 > .GND" to="net.GND" />
<trace from=".U1 > .OUT" to=".U2 > .CLK" />
<trace from=".U2 > .EN" to="net.GND" />
<trace from=".U2 > .RST" to="net.GND" />
{Array.from({ length: 10 }).map((_, i) => {
const angleRadians = Math.PI - (i * (Math.PI / 9));
const radius = 18; // mm
// Calculate X and Y positions based on the angle
const x = Math.cos(angleRadians) * radius;
const y = Math.sin(angleRadians) * radius + 5;
// Rotate the LEDs so they point outward from the center
const rotationDegrees = (angleRadians * 180) / Math.PI - 90;
return (
<group key={`led-channel-${i}`}>
<led
name={`D${i}`}
footprint="0805"
pcbX={x}
pcbY={y}
pcbRotation={rotationDegrees}
/>
<resistor
name={`R${i}`}
resistance="330"
footprint="0603"
pcbX={x}
pcbY={y - 3.5}
pcbRotation={rotationDegrees}
/>
{/* Dynamically route the connections!
1. CD4017 Output Pin -> Resistor
2. Resistor -> LED Positive
3. LED Negative -> Global Ground Net
*/}
<trace from={`.U2 > .${cd4017Outputs[i]}`} to={`.R${i} > .pin1`} />
<trace from={`.R${i} > .pin2`} to={`.D${i} > .pos`} />
<trace from={`.D${i} > .neg`} to="net.GND" />
</group>
);
})}
</board>
);
}