Skip to content

Instantly share code, notes, and snippets.

@smiler
Created February 17, 2014 09:42
Show Gist options
  • Save smiler/9047635 to your computer and use it in GitHub Desktop.
Save smiler/9047635 to your computer and use it in GitHub Desktop.
$fn = 99;
base_height = 5; // Height of base plate
hz = -2; // Extra height of holes
hh = abs(hz)*2 + base_height; // Height of hole cut cylinder
module main() {
difference() {
base();
mounting_holes();
button_hole();
speaker_hole();
knob_hole();
}
//%draw_mtw();
}
/**
* Base plate.
*/
module base() {
w=100;
h=96;
difference() {
cube([w, h, base_height]);
translate([10, 26.5+6, hz]) {
cube([80, 52, hh]);
}
// Top fillets
// Left
translate([0, h / 2, base_height]) {
rotate([0, -90, 90]) {
fillet(2, $fn=99);
}
}
// Bottom
translate([w / 2, 0, base_height]) {
rotate([0, -90, 180]) {
fillet(2, $fn=99);
}
}
// Right
translate([w, h / 2, base_height]) {
rotate([0, -90, -90]) {
fillet(2, $fn=99);
}
}
// Top
translate([w / 2, h, base_height]) {
rotate([0, -90, 0]) {
fillet(2, $fn=99);
}
}
// Corner fillets
// Bottom left
translate([5+2, 5+2, 0]) {
rotate([0, 0, 180]) {
partial_rotate_extrude(90, 5, 5) {
corner_fillet(5, 2, 6);
}
}
}
// Bottom right
translate([w-5-2, 5+2, 0]) {
rotate([0, 0, -90]) {
partial_rotate_extrude(90, 5, 5) {
corner_fillet(5, 2, 6);
}
}
}
// Top right
translate([w-5-2, h-5-2, 0]) {
rotate([0, 0, 0]) {
partial_rotate_extrude(90, 5, 5) {
corner_fillet(5, 2, 5);
}
}
}
// Top left
translate([5+2, h-5-2, 0]) {
rotate([0, 0, 90]) {
partial_rotate_extrude(90, 5, 5) {
corner_fillet(5, 2, 5);
}
}
}
// Cut for LCD backlight part
// translate([4.5, 26.5+6, hz]) {
// cube([7, 53, -hz + 4]);
// }
}
}
/**
* Holes for mounting the board and foot.
*/
module mounting_holes() {
// Bottom left
translate([6.5, 26.8, hz]) {
polyhole(3, hh);
sink(7.0);
}
// Top left
translate([6.5, 96-5, hz]) {
polyhole(3, hh);
sink(7.0);
}
// Top right
translate([100-6.5, 96-5, hz]) {
polyhole(3, hh);
sink(7.0);
}
// Bottom right
translate([100-6.5, 26.8, hz]) {
polyhole(3, hh);
sink(7.0);
}
// Base mounting holes
translate([37, 5, hz]) {
// Bottom left
polyhole(3, hh);
sink(7.0);
// Top
translate([5, 10, 0]) {
polyhole(3, hh);
sink(7.0);
}
// Bottom right
translate([10, 0, 0]) {
polyhole(3, hh);
sink(7.0);
}
}
}
/**
* Hole for button.
*/
module button_hole() {
d = 2.5;
d_2 = d/2;
translate([100-45-d_2, 15, hz]) {
polyhole(d, hh);
}
}
/**
* Hole for speaker.
*/
module speaker_hole() {
d = 14; // Hole diameter
d_2 = d/2;
ph = 2; // Thickness of protective layer
translate([100-24-d_2, 15, 0]) {
difference() {
translate([0, 0, hz])
polyhole(d, hh);
translate([-d_2 - 1, -d_2 - 0.5, base_height - ph]) {
for(i = [1:3:d]) {
translate([i, 0, 0]) {
cube([2, d + 1, ph + 0.2]);
}
}
}
}
}
}
/**
* Hole for knob.
*/
module knob_hole() {
d_2 = 9.5/2; // To center hole
translate([100-8.5-d_2, 15, hz]) {
polyhole(9.5, hh);
}
}
/**
* Polyhole with diameter d around current position.
*/
module polyhole(d,h) {
n = max(round(2 * d),3);
rotate([0,0,180])
cylinder(h = h, r = (d / 2) / cos (180 / n), $fn = n);
}
/**
* Make sink for screw. Assumes being at height hz.
*/
module sink(diameter) {
translate([0, 0, -hz + base_height - 2.3]) {
polyhole(diameter, hh);
}
}
/**
* Creates negative of fillet, i.e. thing to be substracted from object.
*/
module fillet(radius, height=100, $fn=16) {
translate([-radius, -radius, -height/2-0.01])
difference() {
cube([radius*2, radius*2, height+0.02]);
cylinder(r=radius, h=height+0.02, $fn);
}
}
/**
* Creates negative 2d shape for a corner fillet.
*/
module corner_fillet(height, fillet_radius, pad) {
difference() {
polygon([[0, 0], [0, height + pad], [fillet_radius + pad, height + pad], [fillet_radius + pad, 0]]);
translate([0, height-fillet_radius]) {
union() {
circle(fillet_radius);
polygon([[0, 0], [fillet_radius, 0], [fillet_radius, -height+fillet_radius], [0, -height+fillet_radius]]);
}
}
}
}
/**
* Creates pie shaped pieces.
*/
module pie_slice(radius, angle, step) {
for(theta = [0:step:angle-step]) {
rotate([0,0,0])
linear_extrude(height = radius*2, center=true)
polygon(
points = [
[0,0],
[radius * cos(theta+step) ,radius * sin(theta+step)],
[radius*cos(theta),radius*sin(theta)]
]
);
}
}
/**
* Partial circle rotatational extrusion.
*/
module partial_rotate_extrude(angle, radius, convex) {
intersection () {
rotate_extrude(convexity=convex)
translate([radius,0,0])
child(0);
pie_slice(radius*2, angle, angle/5);
}
}
module draw_mtw() {
translate([50, 96 /2, 0]) {
import("LCD Side Mount Faceplate.stl");
rotate([15, 0, 0])
translate([-8, -104, 10] ) {
rotate([-90, -90, 0]) {
import("LCD Side Mount Base.stl");
}
}
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment