Skip to content

Project: Lego Toggle Switch

pentacular edited this page Aug 6, 2019 · 5 revisions

Open #lego-toggle-switch

const Block = ({ studWidth = 1, studLength = 2, plateHeight = 3 } = {}) => {
  const height = plateHeight * 3.2;
  const width = studWidth * 8;
  const length = studLength * 8;

  const Connector = () =>
    assemble(
      Lego
        .studSheet({ width, length, height: 3.2 })
        .above()
        .move(0, 0, height - 3.2)
        .material('plastic')
        .as('studs'),
      Lego
        .socketSheet({ width, length, height: 1, stud: { height: 3 } })
        .above()
        .material('plastic')
        .as('sockets'),
      );

  const Pin = () =>
    Cube(3, 3, 3.2 * 2)
      .move(0, 0, 3.2 * 2);
      
  const Channel = () =>
    Cube(width - 0.2, 3, 2)
      .move(0, 0, 1 + 3.2);
      
  return assemble(
           Cube(width - 0.2, length - 0.2, height - 0.2)
             .above()
             .material('plastic')
             .as('Body'),
           Connector()
             .as('Connector'),
           Channel()
             .as('Channel'),
           Pin()
             .as('Pin'),
         );
}

const ToggleSwitch = () =>
  Cube(7.2, 7.2, 6.2)
    .above(Cube(6, 6, 1));

const FrameBase = () =>
  Cube(16 + 0.2, 16 - 0.2, 3.2 + 1)
    .below();

const frame =
  assemble(
    FrameBase()
      .below()
      .as('FrameBase'),
    Block()
      .scale([-1, 1, 1])
      .move(12 - 4, 0, -3.2 * 3)
      .as('LeftBlock'),
    Block()
      .move(-12 + 4, 0, -3.2 * 3)
      .as('RightBlock'),
    ToggleSwitch()
      .below()
      .move(0, 0, 3)
      .as('ToggleSwitch'),
    );

frame
  .drop('Channel', 'Pin', 'ToggleSwitch')
  .writeStl('lego_toggle_switch_frame.stl');

frame
  .keep('Pin')
  .writeStl('lego_toggle_switch_pin.stl');

frame
  .withWireframe();
Clone this wiki locally