hrithik18k/smart-switch-touch
A 45×40 mm four-key capacitive touch panel using a TTP224C controller, touch electrodes, four red LEDs with 220 Ω resistors, filtering/tuning capacitors, and host/indicator wire-land connectors.
- Version
- 1.1.0
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone hrithik18k/smart-switch-touch # download the package files into ./smart-switch-touch
tsci add hrithik18k/smart-switch-touch # add it to your project as @tsci/hrithik18k.smart-switch-touchIn a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
index.circuit.tsx
PCB
Schematic
import { Fragment } from "react"
import { A_0603WAF2200T5E } from "./imports/A_0603WAF2200T5E"
import { CC0603KRX7R9BB104 } from "./imports/CC0603KRX7R9BB104"
import { CL10C100JB8NNNC } from "./imports/CL10C100JB8NNNC"
import { E6Q1206URAC1UDA } from "./imports/E6Q1206URAC1UDA"
import { TTP224C_BSBN } from "./imports/TTP224C_BSBN"
// The solder-mask-covered electrode side is the faceplate side.
// Bottom-side viewing flips X, so the front reads 1, 2 / 3, 4.
const keys = [
{ number: 1, x: 13.5, y: 11, input: "TP0", output: "TPQ0", trimX: -5.6, trimY: -1.2 },
{ number: 2, x: -13.5, y: 11, input: "TP1", output: "TPQ1", trimX: -5.6, trimY: -4.3 },
{ number: 3, x: 13.5, y: -11, input: "TP2", output: "TPQ2", trimX: -1.5, trimY: -7.5 },
{ number: 4, x: -13.5, y: -11, input: "TP3", output: "TPQ3", trimX: 2.0, trimY: -8.4 },
]
const harness = ["3V3", "GND", "OUT1", "OUT2", "OUT3", "OUT4"]
const indicatorHarness = ["LED1", "LED2", "LED3", "LED4", "GND"]
function WireLands({ labels, labelOffset }: { labels: string[]; labelOffset: number }) {
return (
<footprint insertionDirection="from_above">
{labels.map((label, index) => {
const x = (index - (labels.length - 1) / 2) * 2.54
return (
<Fragment key={label}>
<platedhole name={label} shape="circle" pcbX={x} pcbY={0} holeDiameter="1mm" outerDiameter="1.8mm" portHints={[`pin${index + 1}`]} />
<silkscreentext text={label} pcbX={x} pcbY={labelOffset} fontSize="0.85mm" />
</Fragment>
)
})}
</footprint>
)
}
export default function SmartSwitchTouchPanel() {
return (
<board
width="45mm"
height="40mm"
thickness="1.6mm"
layers={2}
minTraceWidth="0.15mm"
minViaHoleDiameter="0.3mm"
minViaPadDiameter="0.6mm"
minTraceToPadEdgeClearance="0.15mm"
minPadEdgeToPadEdgeClearance="0.15mm"
>
<schematicsection name="Sense" displayName="Keys" />
<schematicsection name="Control" displayName="Touch controller" />
<schematicsection name="Interface" displayName="Host interface" />
<schematicsection name="Indicators" displayName="Status LEDs" />
<net name="VCC" />
<net name="GND" />
<TTP224C_BSBN
name="U1"
manufacturerPartNumber="TTP224C-BSBN"
schSectionName="Control"
schX={0}
schY={0}
schPinArrangement={{
leftSide: ["TP0", "TP1", "TP2", "TP3", "AHLB", "TOG", "SM", "OD"],
rightSide: ["TPQ0", "TPQ1", "TPQ2", "TPQ3", "VDD", "LPMB", "VSS", "MOT0"],
}}
pinAttributes={{
TP0: { isInput: true },
TP1: { isInput: true },
TP2: { isInput: true },
TP3: { isInput: true },
VDD: { requiresPower: true },
VSS: { requiresGround: true },
LPMB: { isInput: true },
AHLB: { doNotConnect: true },
TOG: { doNotConnect: true },
MOT0: { doNotConnect: true },
SM: { doNotConnect: true },
OD: { doNotConnect: true },
TPQ0: { isOutput: true },
TPQ1: { isOutput: true },
TPQ2: { isOutput: true },
TPQ3: { isOutput: true },
}}
pcbX={0}
pcbY={0}
/>
<CC0603KRX7R9BB104 name="C1" schSectionName="Control" schX={1} schY={-3.5} schRotation={-90} pcbX={4.8} pcbY={-3} />
<trace from=".U1 > .VDD" to="net.VCC" />
<trace from=".U1 > .LPMB" to="net.VCC" />
<trace from=".U1 > .VSS" to="net.GND" />
<trace from=".C1 > .pin1" to="net.VCC" />
<trace from=".C1 > .pin2" to="net.GND" />
{/* AHLB, TOG, OD, SM and MOT0 are internally biased by U1. */}
{keys.map(({ number, x, y, input, output, trimX, trimY }, index) => (
<Fragment key={number}>
<net name={`SENSE${number}`} />
<net name={`OUT${number}`} />
<net name={`LED${number}`} />
<chip
name={`E${number}`}
manufacturerPartNumber="PCB touch electrode"
doNotPlace
pinLabels={{ pin1: "ELECTRODE", pin2: "UPPER", pin3: "OUTER", pin4: "LOWER" }}
pinAttributes={{
ELECTRODE: { isPassive: true },
UPPER: { isPassive: true },
OUTER: { isPassive: true },
LOWER: { isPassive: true },
}}
internallyConnectedPins={[[1, 2, 3, 4]]}
schSectionName="Sense"
schX={-10}
schY={4.5 - 3 * index}
pcbX={x}
pcbY={y}
layer="bottom"
footprint={
<footprint>
{/* The four overlapping lands form one continuous electrode.
Pin 1 anchors the route on the inner edge of the key. */}
<smtpad shape="rect" pcbX={3.7 * Math.sign(x)} pcbY={0} width="4.6mm" height="3.4mm" coveredWithSolderMask portHints={["pin1"]} />
<smtpad shape="rect" pcbX={0} pcbY={3.7} width="12mm" height="4.6mm" coveredWithSolderMask portHints={["pin2"]} />
<smtpad shape="rect" pcbX={-3.7 * Math.sign(x)} pcbY={0} width="4.6mm" height="3.4mm" coveredWithSolderMask portHints={["pin3"]} />
<smtpad shape="rect" pcbX={0} pcbY={-3.7} width="12mm" height="4.6mm" coveredWithSolderMask portHints={["pin4"]} />
<silkscreentext text={String(number)} fontSize="1.6mm" pcbX={0} pcbY={-3.4} />
</footprint>
}
/>
{/* Only the narrow center corridor carries LED wiring behind the electrode. */}
<keepout shape="rect" layers={["top"]} pcbX={x} pcbY={y + 4} width="12.4mm" height="4.4mm" />
<keepout shape="rect" layers={["top"]} pcbX={x} pcbY={y - 4} width="12.4mm" height="4.4mm" />
<E6Q1206URAC1UDA
name={`D${number}`}
color="red"
schSectionName="Indicators"
schX={13 + 2 * index}
schY={0}
schRotation={-90}
pcbX={x}
pcbY={y}
pcbRotation={x > 0 ? 180 : 0}
/>
<A_0603WAF2200T5E
name={`R${number}`}
schSectionName="Indicators"
schX={13 + 2 * index}
schY={2.4}
schRotation={-90}
pcbX={Math.sign(x) * 5.6}
pcbY={y}
pcbRotation={x > 0 ? 0 : 180}
/>
<CL10C100JB8NNNC
name={`C${number + 1}`}
schSectionName="Sense"
schX={-6}
schY={4.5 - 3 * index}
schRotation={-90}
pcbX={trimX}
pcbY={trimY}
doNotPlace
/>
<trace from={`.E${number} > .pin1`} to={`net.SENSE${number}`} />
<trace from={`.U1 > .${input}`} to={`net.SENSE${number}`} />
<trace from={`.C${number + 1} > .pin1`} to={`net.SENSE${number}`} />
<trace from={`.C${number + 1} > .pin2`} to="net.GND" />
<trace from={`.U1 > .${output}`} to={`net.OUT${number}`} />
<trace from={`.J1 > .pin${number + 2}`} to={`net.OUT${number}`} />
<trace from={`.J2 > .pin${number}`} to={`net.LED${number}`} />
<trace from={`.R${number} > .pin1`} to={`net.LED${number}`} />
<trace from={`.R${number} > .pin2`} to={`.D${number} > .anode`} />
<trace from={`.D${number} > .cathode`} to="net.GND" />
</Fragment>
))}
<connector
name="J1"
manufacturerPartNumber="PCB wire lands"
doNotPlace
pinLabels={{ pin1: "VCC", pin2: "GND", pin3: "OUT1", pin4: "OUT2", pin5: "OUT3", pin6: "OUT4" }}
pinAttributes={{
VCC: { providesPower: true, providesVoltage: "3.3V" },
GND: { providesGround: true },
OUT1: { isPassive: true },
OUT2: { isPassive: true },
OUT3: { isPassive: true },
OUT4: { isPassive: true },
}}
schSectionName="Interface"
schX={7}
schY={1.5}
schWidth={1.46}
schPinArrangement={{ leftSide: [1, 2, 3, 4, 5, 6] }}
pcbX={0}
pcbY={18.35}
footprint={<WireLands labels={harness} labelOffset={-1.8} />}
/>
<trace from=".J1 > .pin1" to="net.VCC" />
<trace from=".J1 > .pin2" to="net.GND" />
<connector
name="J2"
manufacturerPartNumber="PCB wire lands"
doNotPlace
pinLabels={{ pin1: "LED1", pin2: "LED2", pin3: "LED3", pin4: "LED4", pin5: "GND" }}
pinAttributes={{
LED1: { isPassive: true },
LED2: { isPassive: true },
LED3: { isPassive: true },
LED4: { isPassive: true },
GND: { isPassive: true },
}}
schSectionName="Indicators"
schX={17}
schY={4.65}
symbol={
<symbol>
<schematicrect schX={0} schY={0} width={9.4} height={0.8} isFilled={false} />
<schematictext text="J2" schX={-4.35} schY={0.7} fontSize={0.19} />
{indicatorHarness.map((label, index) => {
const pinX = 2 * (index - 2)
return (
<Fragment key={label}>
<schematictext text={label} schX={pinX} schY={0} anchor="center" fontSize={0.19} />
<port name={label} pinNumber={index + 1} direction="down" schX={pinX} schY={-0.8} schStemLength={0.4} />
</Fragment>
)
})}
</symbol>
}
pcbX={0}
pcbY={-18.35}
footprint={<WireLands labels={indicatorHarness} labelOffset={1.8} />}
/>
<trace from=".J2 > .pin5" to="net.GND" />
</board>
)
}