Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Last active August 14, 2024 20:32
Show Gist options
  • Save rocktronica/03296b011a62f017e908382a4929c86b to your computer and use it in GitHub Desktop.
Save rocktronica/03296b011a62f017e908382a4929c86b to your computer and use it in GitHub Desktop.
// Size 4-40
screwDiameter = 2.8;
screwHeadDiameter = 5.5;
screwHeadHeight = 2.3;
insertDiameter = 4;
insertThreadedDiameter = 4.45;
insertHeight = 3.5;
standardPotShaftTopHeight = 8;
standardPotShaftTopDiameter = 6;
standardFlattedDepth = standardPotShaftTopDiameter - 4.5;
minimumKnobHeightFromShaft = 2;
minimumKnobHeight = standardPotShaftTopHeight + minimumKnobHeightFromShaft;
potKnobDefaultShimCount = 3;
module pot_knob(
knobDiameter = 15,
knobHeight = minimumKnobHeight,
knobColor = [.1,.1,.1,1],
innerColor = undef,
shaftDiameter = standardPotShaftTopDiameter,
shaftHeight = standardPotShaftTopHeight,
showChamfer = true,
markerHeight = 1,
markerWidth = 2,
markerRotation = 0,
markerColor = "white",
showMarker = true,
invertMarker = false,
shimWidth = 1,
shimLength = .5,
shimCount = potKnobDefaultShimCount,
tightenerDiameter = 0,
recessHeight = 0,
recessDiameter = 0,
flatted = false,
flatDepth = standardFlattedDepth,
flatTolerance = undef,
$fn = 100,
debug = false,
tolerance = .25,
previewGutter = .1
) {
useSkirt = recessHeight > 0 && recessDiameter > 0;
recessHeight = useSkirt ? recessHeight : 0;
recessDiameter = useSkirt ? recessDiameter : 0;
shaftHeight = useSkirt ? shaftHeight + recessHeight : shaftHeight;
innerColor = innerColor == undef
? knobColor
: innerColor;
module standard_pot_flat_cutout(
rotation = -markerRotation,
depth = flatDepth - (flatTolerance == undef ? tolerance : flatTolerance)
) {
width = shaftDiameter + previewGutter * 2;
length = shaftDiameter; // arbitrary
rotate([0, 0, rotation]) {
translate([
width / -2,
-length - (shaftDiameter + tolerance * 2) / 2 + depth,
-previewGutter
]) {
cube([width, length, shaftHeight + previewGutter * 2]);
}
}
}
module outer() {
cylinder(
d = knobDiameter,
h = knobHeight
);
}
module shims() {
offset = shimCount == 1
? 0
: (360 / shimCount / 2) - markerRotation;
for (i = [0 : shimCount]) {
rotate([0, 0, offset + 360 * (i / shimCount)]) {
translate(
[(shimWidth / -2),
shaftDiameter / 2 - shimLength + tolerance,
previewGutter * -2
]) {
cube([
shimWidth,
shimLength * 2,
shaftHeight + previewGutter * 3
]);
}
}
}
}
module inner() {
difference() {
translate([0, 0, -previewGutter]) {
cylinder(
d = shaftDiameter + tolerance * 2,
h = shaftHeight + previewGutter
);
}
if (shimCount > 0) {
shims();
}
if (flatted) {
standard_pot_flat_cutout();
}
} // difference
}
module recess() {
translate([0, 0, -previewGutter]) {
cylinder(
d = recessDiameter + tolerance * 2,
h = recessHeight + previewGutter
);
}
}
module marker() {
z = invertMarker
? knobHeight - markerHeight
: knobHeight;
height = invertMarker
? markerHeight + previewGutter
: markerHeight;
rotate([0, 0, markerRotation * -1]) {
translate([(markerWidth / -2), 0, z]) {
cube([markerWidth, knobDiameter / 2, height]);
}
}
}
module shaft_chamfer() {
chamferDiameter = shaftDiameter + 3;
chamferHeight = chamferDiameter / 2;
translate([0, 0, recessHeight - previewGutter]) {
cylinder(
d1 = chamferDiameter,
d2 = 0,
h = chamferHeight + previewGutter
);
}
}
module tightener_cutout() {
wallDepth = (knobDiameter - shaftDiameter) / 2;
headCavityDepth = max(screwHeadHeight, wallDepth - insertHeight);
minimumBaseBeneathHeadDepth = 2;
translate([0, 0, recessHeight + shaftHeight / 2])
rotate([90, 0, 0]) {
cylinder(
d = tightenerDiameter,
h = knobDiameter
);
if (wallDepth >= headCavityDepth + minimumBaseBeneathHeadDepth) {
translate([0, 0, knobDiameter / 2 - headCavityDepth]) {
cylinder(
d = screwHeadDiameter + tolerance * 2,
h = headCavityDepth + previewGutter
);
}
}
}
}
intersection() {
difference() {
color(knobColor) outer();
color(innerColor) {
inner();
if (showChamfer) {
shaft_chamfer();
}
recess();
if (showMarker && invertMarker) {
marker();
}
if (tightenerDiameter > 0) {
tightener_cutout();
}
}
} // difference
if (debug) {
translate([
knobDiameter / -2 - previewGutter,
knobDiameter / -2 - previewGutter,
-previewGutter
]) {
cube([
knobDiameter / 2 + previewGutter,
knobDiameter + previewGutter * 2,
knobHeight + previewGutter * 2
]);
}
}
}
if (showMarker && !invertMarker) {
color(markerColor) {
marker();
}
}
}
@rocktronica
Copy link
Author

Designing Potentiometer Knobs

From the blog post Designing Potentiometer Knobs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment