Files
rp2040-hid/3dprint/buttons.scad

95 lines
2.9 KiB
OpenSCAD

$fa = 1;
$fs = 0.4;
wiggle_room = 0.3;
epsilon = 0.01;
text_depth = 0.4;
button_thickness = 3;
switch_shaft_upper = 3 + wiggle_room;
switch_shaft_lower = 3.5 + wiggle_room;
switch_shaft_length = 8.8;
shaft_outer = 7;
shaft_length = 5;
print_spacing = 10;
module button(label, width, height, size=3) {
difference() {
cube([width, height, button_thickness]);
translate([0, 0, epsilon])
button_text(label, width, height, text_depth+epsilon, size=size);
}
translate([width/2, height/2, 0])
difference() {
translate([0, 0, -shaft_length])
cylinder(h=shaft_length, r=shaft_outer/2);
translate([0, 0, -switch_shaft_length])
cylinder(h=switch_shaft_length, r1=switch_shaft_lower/2,
r2=switch_shaft_upper/2);
}
}
module button_text(label, width, height, thickness, size=3) {
translate([width/2, height/2, button_thickness-thickness])
linear_extrude(thickness)
text(label, font="Orbitron:style=Black",
halign="center", valign="center", size=size);
}
//buttons = ["HDG"];
//buttons_small = [""];
buttons = ["HDG", "LNAV", "ALT", "VNAV",
"VS", "FLC", "SPD", "APR",
"LVL", "FD", "AP", "A/T", "N1"];
buttons_small = ["", "", "c/o"];
button_width = 15;
button_height = 8;
button_small_width = 8;
button_small_height = 8;
render_text = true;
render_button = true;
row_length = 4;
rotate([0, 180, 0]) {
for (i = [0:len(buttons)-1]) {
translate([(i%row_length)*(button_width+print_spacing),
floor(i/row_length)*(button_height+print_spacing), 0]) {
if (render_text && render_button) {
color("black")
button(buttons[i], button_width, button_height);
color("white")
button_text(buttons[i], button_width, button_height, text_depth);
} else if (render_button) {
button(buttons[i], button_width, button_height);
} else if (render_text) {
button_text(buttons[i], button_width, button_height, text_depth);
}
}
}
for (i = [0:len(buttons_small)-1]) {
translate([(i%row_length)*(button_small_width+print_spacing),
floor(i/row_length)*(button_small_height+print_spacing)+80, 0]) {
if (render_text && render_button) {
color("black")
button(buttons_small[i], button_small_width, button_small_height,
size=3);
color("white")
button_text(buttons_small[i], button_small_width,
button_small_height, text_depth, size=3);
} else if (render_button) {
button(buttons_small[i], button_small_width, button_small_height, size=3);
} else if (render_text) {
button_text(buttons_small[i], button_small_width, button_small_height,
text_depth, size=3);
}
}
}
}