// 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; | |
flatTolerance = flatTolerance == undef | |
? tolerance | |
: flatTolerance; | |
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( | |
rotation = -markerRotation, | |
height = shaftHeight, | |
depth = flatDepth - flatTolerance, | |
z = shaftHeight - standardFlatHeight | |
); | |
} | |
} // 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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment