cad/lib/key.scad
Ricardo (XenGi) Band 462d2bfb6c
new stuff
2023-06-06 01:03:09 +02:00

27 lines
1.6 KiB
OpenSCAD

// Generate a key cap at a specific position in the matrix
module key(x, y, w=1, h=1, label="", spacing=1, size=3.5) {
include <key_specs.scad>;
$fn = 64;
color("DarkSlateGray") translate([x*key_width + x*padding + margin, y*key_height + y*padding + margin, mat_thickness]) difference() {
union() {
hull() {
translate([key_radius, key_radius, 0]) cylinder(h=key_thickness, r=key_radius);
translate([key_radius, key_height*h + padding*(h-1) - key_radius, 0]) cylinder(h=key_thickness, r=key_radius);
translate([key_width*w + padding*(w-1) - key_radius, key_radius, 0]) cylinder(h=key_thickness, r=key_radius);
translate([key_width*w + padding*(w-1) - key_radius, key_height*h + padding*(h-1) - key_radius, 0]) cylinder(h=key_thickness, r=key_radius);
}
}
// indent instead of dome
translate([0,0,key_thickness]) hull() {
translate([1.1, 1.1, 0]) scale([1,1,0.3]) sphere(r=1);
translate([key_width*w + padding*(w-1) - 1.1, 1.1, 0]) scale([1,1,0.3]) sphere(r=1);
translate([1.1, key_height*h + padding*(h-1) - 1.1, 0]) scale([1,1,0.3]) sphere(r=1);
translate([key_width*w + padding*(w-1) - 1.1, key_height*h + padding*(h-1) - 1.1, 0]) scale([1,1,0.3]) sphere(r=1);
}
// depth of 0.3mm+
// Noto Sans Mono:style=Medium
// subtract label from key cap
translate([(key_width*w + padding*(w-1))/2 -(0.5/spacing-0.5), (key_height*h + padding*(h-1))/2, key_thickness-0.5]) linear_extrude(height=1) text(label, size=size, font="DejaVu Sans Mono:style=Bold", halign="center", valign="center", spacing=spacing, $fn=64);
}
}