1 ///////////////////////////////////////////////////////////////////////////////
2 // Atreides case file, OpenSCAD laser cut format //
3 // Copyright 2014-2020 Phil Hagelberg, 2021 Armaan Bhojwani, GPLv3 //
4 // All distances are in mm //
5 ///////////////////////////////////////////////////////////////////////////////
7 ///////////////////////////////////////////////////////////////////////////////
9 ///////////////////////////////////////////////////////////////////////////////
14 // Distance between key centers.
16 row_spacing = column_spacing;
18 /* This number should exceed row_spacing and column_spacing. The default gives
19 a 1mm = (20mm - 19mm) gap between keycaps and cuts in the top plate. */
22 // The angle between the halves is twice this number
25 /* This constant allows tweaking the location of the screw holes near the USB
26 cable. Only useful with small `angle` values. Try the value of 10 with
28 back_screw_hole_offset = 0;
30 /* The radius of screw holes. Holes will be slightly bigger due to the cut
32 screw_hole_radius = 1.5;
34 /* Each screw hole is a hole in a "washer". How big these "washers" depends on
35 the material used: this parameter and the `switch_hole_size` determine the
36 spacer wall thickness. */
37 washer_radius = 4 * screw_hole_radius;
39 /* The approximate size of switch holes. Used to determine how thick walls can
40 be, i.e. how much room around each switch hole to leave. See spacer(). */
41 switch_hole_size = 14;
43 // Distance between halves.
44 hand_separation = key_hole_size - switch_hole_size;
46 /* Number of rows and columns in the matrix. You need to update
47 staggering_offsets if you change n_cols. */
51 // The width of the USB cable hole in the spacer.
52 cable_hole_width = 12;
54 // Vertical column staggering offsets. The first element should be zero.
55 staggering_offsets = [0, 5, 11, 6, 3];
57 // Width and height between screw holes of OLED
61 ///////////////////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////////////////
65 module rz(angle, center=undef) {
66 // Rotate children `angle` degrees around `center`.
70 for (i=[0:$children-1])
77 /* Compute coordinates of a point obtained by rotating p angle degrees around
78 center. Used to compute locations of screw holes near the USB cable hole. */
79 function rz_fun(p, angle, center) = [
80 cos(angle) * (p[0] - center[0]) - sin(angle) * (p[1] - center[1]) + center[0],
81 sin(angle) * (p[0] - center[0]) + cos(angle) * (p[1] - center[1])+ center[1]];
83 /* Cherry MX switch hole with the center at `position`. Sizes come from the
85 module switch_hole(position) {
88 notch_offset = 4.2545;
91 square([hole_size, hole_size], center=true);
95 // Create a hole for a regular key
96 module regular_key(position, size) {
98 square([size, size], center=true);
102 // Create a column of keys
103 module column (bottom_position, switch_holes, key_size=key_hole_size,
105 translate(bottom_position) {
106 for (i = [0:(rows-1)]) {
107 if (switch_holes == true) {
108 switch_hole([0, i*column_spacing]);
110 regular_key([0, i*column_spacing], key_size);
116 /* Rotate the right half of the keys around the top left corner of the thumb
117 key. Assumes that the thumb key is a 1x1.5 key and that it is shifted
118 0.5*column_spacing up relative to the nearest column. */
119 module rotate_half() {
120 rotation_y_offset = 1.75 * column_spacing;
121 for (i=[0:$children-1]) {
122 rz(angle, [hand_separation, rotation_y_offset]) {
128 // Shift everything right to get desired hand separation
129 module add_hand_separation() {
130 for (i=[0:$children-1]) {
131 // Half the value because when it is mirrored, it gets cancelled out
132 translate([0.5*hand_separation, 0]) children(i);
136 module screw_hole(radius, offset_radius, position=[0,0], direction=[0,0]) {
137 /* Create a screw hole of radius `radius` at a location `offset_radius` from
138 `position`, (diagonally), in the direction `direction`. Oh, what a mess
141 direction is the 2-element vector specifying to which side of position to
142 move to, [-1, -1] for bottom left, etc.
144 radius_offset is the offset in the x (or y) direction so that we're
145 offset_radius from position */
146 radius_offset = offset_radius / sqrt(2);
148 // key_hole_offset if the difference between key spacing and key hole edge
149 key_hole_offset = 0.5*(row_spacing - key_hole_size);
150 x = position[0] + (radius_offset - key_hole_offset) * direction[0];
151 y = position[1] + (radius_offset - key_hole_offset) * direction[1];
157 // Create screw holes for the oled screen
158 module oled_holes(hole_radius) {
160 translate([-oled_width/2,-oled_height/2]) {
161 translate([0, oled_height]) {
162 screw_hole(hole_radius, washer_radius);
164 translate([oled_width, oled_height]) {
165 screw_hole(hole_radius, washer_radius);
167 translate([oled_width, 0]) {
168 screw_hole(hole_radius, washer_radius);
170 screw_hole(hole_radius, washer_radius);
176 // Passthrough in switch plate for the OLED cables
177 module oled_passthrough() {
179 square([14, 8], center=true);
183 module right_screw_holes(hole_radius) {
184 // Coordinates of the back right screw hole before rotation...
185 back_right = [(n_cols+2)*row_spacing,
186 staggering_offsets[n_cols-1] + n_rows * column_spacing];
189 tmp = rz_fun(back_right, angle, [0, 2.25*column_spacing]);
194 add_hand_separation() {
195 screw_hole(hole_radius, washer_radius,
198 screw_hole(hole_radius, washer_radius,
199 [(n_cols+2)*row_spacing, staggering_offsets[n_cols-1]],
201 screw_hole(hole_radius, washer_radius,
207 // Add the screw hole near the cable hole
208 translate([washer_radius - tmp[0] - 0.5*hand_separation,
209 back_screw_hole_offset]) {
211 add_hand_separation() {
212 screw_hole(hole_radius, washer_radius, back_right, [nudge, nudge]);
218 // Create all the screw holes
219 module screw_holes(hole_radius) {
220 right_screw_holes(hole_radius);
221 mirror ([1,0,0]) { right_screw_holes(hole_radius); }
224 ///////////////////////////////////////////////////////////////////////////////
226 ///////////////////////////////////////////////////////////////////////////////
228 /* Create switch holes or key holes for the right half of the
229 keyboard. Different key_sizes are used in top_plate() and
231 module right_half(switch_holes=true, key_size=key_hole_size) {
232 x_offset = 0.5 * row_spacing;
233 y_offset = 0.5 * column_spacing;
234 thumb_key_offset = y_offset + 0.25 * column_spacing;
236 add_hand_separation() {
239 column([x_offset + (j)*row_spacing, y_offset], switch_holes,
243 for (j=[0:(n_cols-1)]) {
244 column([x_offset + (j+2)*row_spacing,
245 y_offset + staggering_offsets[j]], switch_holes, key_size);
251 // Mirror the right half to create the left half
252 module left_half(switch_holes=true, key_size=key_hole_size) {
254 right_half(switch_holes, key_size);
258 // Create the bottom layer of the case
259 module bottom_plate() {
262 screw_holes(washer_radius);
264 screw_holes(screw_hole_radius);
268 // Create the top layer of the case
274 oled_holes(screw_hole_radius);
278 // Create the switch plate
279 module switch_plate() {
288 // Create a spacer layer
295 right_half(switch_holes=false, key_size=switch_hole_size + 3);
296 left_half(switch_holes=false, key_size=switch_hole_size + 3);
298 // Add the USB cable hole
299 translate([-0.5*cable_hole_width+100, 2*column_spacing]) {
300 square([cable_hole_width, (2*n_rows) * column_spacing]);
303 screw_holes(washer_radius);
305 screw_holes(screw_hole_radius);
313 // Display all five layers
316 translate([350, 0]) {
320 translate([0, 175]) {
324 translate([350, 175]) {
328 /* translate([550, 0]) { */
332 ///////////////////////////////////////////////////////////////////////////////