Parametric OpenSCAD Designs

Case for thin PCBs

inch2mm = 25.4;

xlen = 1.9 * inch2mm;   // Board measurements - length
ylen = 1.015 * inch2mm; // Board measurements - width
boardheight = 4;        // Board measurements - height

hole_diameter = 3;      // Board mounting holes - diameter
hole_spacing  = 1;      // Board mounting holes - spacing from the board-edges

baseheight = 2;         // Case base measurements - bottom panel
wallwidth = 1;          // Case wall measurements - side-walls

module xhole_plate(size, h_dm, hole_count, hole_margin) {
  difference() {
    cube(size);

    abs_margin  = hole_margin + h_dm/2;
    x_hole_dist = (size.x - 2*abs_margin) / (hole_count.x - 1);
    y_hole_dist = (size.y - 2*abs_margin) / (hole_count.y - 1);
    x_values    = [abs_margin : x_hole_dist : size.x - abs_margin + 0.1];
    y_values    = [abs_margin : y_hole_dist : size.y - abs_margin + 0.1];

    // holes
    for (x = x_values, y = y_values)
      translate( [x, y, -1] )
        color( "red" )
          cylinder( d = h_dm, h = size.z + 2, $fn=20);
  }
}

module prism(l, w, h){
  polyhedron(
    points=[[0,0,0], [l,0,0], [l,w,0], [0,w,0], [0,w,h], [l,w,h]],
    faces=[[0,1,2,3],[5,4,3,2],[0,4,5,1],[0,3,4],[5,2,1]]
   );
}

union() {
  xhole_plate(
    [xlen, ylen, baseheight],
    hole_diameter,
    [2,2],
    hole_spacing
  );

  color("green") {
    translate([xlen, -wallwidth, 0])
      cube([wallwidth, ylen + 2*wallwidth, baseheight + boardheight]);

    translate([0, ylen, 0])
      cube([xlen, wallwidth, baseheight + boardheight]);

    translate([0, -wallwidth, 0])
      cube([xlen, wallwidth, baseheight + boardheight]);
  }

  color("blue"){
    translate([10, -wallwidth, baseheight + boardheight])
      cube([xlen - 2*10 + wallwidth, ylen + 2*wallwidth, wallwidth]);

    rotate([0, 0, 270]) {
      translate([0, 0, baseheight + boardheight])
        prism(wallwidth, 10, wallwidth);

      translate([-ylen - wallwidth, 0, baseheight + boardheight])
        prism(wallwidth, 10, wallwidth);
    }
  }
}