seveibar/keyboard-sample

A tscircuit package created by seveibar.

Usage: For "@tsci/seveibar.keyboard-sample": 1. Import the component: ```tsx import KeyboardSample from "@tsci/seveibar.keyboard-sample" ``` 2. Use the component in a React-like circuit design: ```tsx <board> <KeyboardSample sampleNumber={3} /> </board> ``` The component takes an optional `sampleNumber` parameter to define the grid size of the keyboard matrix (defaults to 2). It automatically generates a keyboard matrix with keys, diodes, and traces connecting to a Pico2 microcontroller.

Version
0.0.1
License
unset
Stars
0

dist/index.js

PCBPCB preview for dist/index.js
SchematicSchematic preview for dist/index.js
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _seveibar = require("@tsci/seveibar.SmdDiode");
var _seveibar2 = require("@tsci/seveibar.Key");
var _seveibar3 = require("@tsci/seveibar.pico2");
function grid(opts) {
  const {
    sizeX,
    sizeY,
    pitch,
    offset = {
      x: 0,
      y: 0
    }
  } = opts;
  const points = [];
  const startX = -(sizeX - 1) * pitch / 2;
  const startY = -(sizeY - 1) * pitch / 2;
  for (let row = 0; row < sizeY; row++) {
    for (let col = 0; col < sizeX; col++) {
      points.push({
        x: startX + col * pitch + offset.x,
        y: startY + row * pitch + offset.y,
        row,
        col
      });
    }
  }
  return points;
}
const rowToMicroPin = {
  0: "GP0",
  1: "GP1",
  2: "GP10"
};
const colToMicroPin = {
  0: "GP19",
  1: "GP17",
  2: "GP5"
};
var _default = ({
  sampleNumber = 2
}) => {
  return /*#__PURE__*/React.createElement("board", {
    width: "100mm",
    height: "100mm",
    routingDisabled: true
  }, /*#__PURE__*/React.createElement(_seveibar3.Pico2, {
    name: "U1",
    pcbX: -30
  }), grid({
    sizeX: sampleNumber,
    sizeY: sampleNumber,
    pitch: 19.05,
    offset: {
      x: 20,
      y: 0
    }
  }).map(({
    x,
    y,
    row,
    col
  }, index) => /*#__PURE__*/React.createElement("group", {
    key: `Kgroup${index}`
  }, /*#__PURE__*/React.createElement(_seveibar2.Key, {
    pcbX: x,
    pcbY: y,
    name: `K${index + 1}`
  }), /*#__PURE__*/React.createElement(_seveibar.SmdDiode, {
    pcbX: x,
    pcbY: y - 13,
    layer: "bottom",
    name: `D${index + 1}`
  }), /*#__PURE__*/React.createElement("trace", {
    from: `.D${index + 1} .pin1`,
    to: `.K${index + 1} .pin1`
  }), /*#__PURE__*/React.createElement("trace", {
    from: `.D${index + 1} .pin2`,
    to: `.U1 .${rowToMicroPin[row]}`
  }), /*#__PURE__*/React.createElement("trace", {
    from: `.K${index + 1} .pin2`,
    to: `.U1 .${colToMicroPin[col]}`
  }))));
};
exports.default = _default;