Skip to content

Commit 3c12b36

Browse files
committed
adding rotary trinkey crank inital files
1 parent 50f62d2 commit 3c12b36

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
shaft_cutout = 6.2 + 1.7;
2+
3+
Z_HEIGHT = 30;
4+
X_HEIGHT = 36;
5+
Y_HEIGHT = 38;
6+
THICKNESS = 1.5 * 2;
7+
8+
USB_CUTOUT_Z = 20;
9+
USB_CUTOUT_X = 17;
10+
USB_CUTOUT_Y = 40;
11+
12+
TAB_SIZE = 6;
13+
TAB_HEIGHT = 2;
14+
TAB_TOLERANCE = 0.1;
15+
16+
USB_WALL_OFFSET = 1;
17+
18+
/*
19+
difference(){
20+
cube([X_HEIGHT, Y_HEIGHT, Z_HEIGHT], center=true);
21+
translate([0,0,THICKNESS/2])
22+
cube([X_HEIGHT-THICKNESS, Y_HEIGHT-THICKNESS, Z_HEIGHT], center=true);
23+
24+
translate([10,-3,0])
25+
rotate([0,90,0])
26+
cylinder(r=shaft_cutout/2, h=40, center=true, $fn=30);
27+
28+
translate([X_HEIGHT/2 - USB_CUTOUT_X/2 - THICKNESS/2 - USB_WALL_OFFSET,20,0])
29+
cube([USB_CUTOUT_X, USB_CUTOUT_Y, USB_CUTOUT_Z], center=true);
30+
}*/
31+
32+
33+
/*
34+
translate([7.5,20.5 - 3,0])
35+
rotate([-90,0,-90])
36+
import("4964 Rotary Trinkey.stl");
37+
*/
38+
39+
module close_tab(){
40+
difference(){
41+
cube([TAB_SIZE,TAB_SIZE,TAB_HEIGHT], center=true);
42+
translate([1.5, 1.5, 0])
43+
cube([TAB_SIZE,TAB_SIZE,TAB_HEIGHT+1], center=true);
44+
}
45+
}
46+
47+
48+
module lid(){
49+
cube([X_HEIGHT, Y_HEIGHT, THICKNESS/2], center=true);
50+
51+
translate([
52+
-X_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
53+
-Y_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
54+
THICKNESS/4 + 2/2
55+
])
56+
close_tab();
57+
58+
translate([
59+
X_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
60+
Y_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
61+
THICKNESS/4 + 2/2
62+
])
63+
rotate([0,0,180])
64+
close_tab();
65+
66+
translate([
67+
X_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
68+
-Y_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
69+
THICKNESS/4 + 2/2
70+
])
71+
rotate([0,0,90])
72+
close_tab();
73+
74+
translate([
75+
-X_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
76+
Y_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
77+
THICKNESS/4 + 2/2
78+
])
79+
rotate([0,0,270])
80+
close_tab();
81+
}
82+
83+
translate([0,0,16])
84+
//rotate([0,180,0])
85+
lid();
86+
87+
//translate([0, Y_HEIGHT/2-1, 10])
88+
//cube([1,1,1], center=true);
Binary file not shown.
Binary file not shown.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import time
2+
import board
3+
import digitalio
4+
import rotaryio
5+
import math
6+
import usb_hid
7+
from adafruit_hid.consumer_control import ConsumerControl
8+
from adafruit_hid.consumer_control_code import ConsumerControlCode
9+
10+
11+
STAY_EVEN_CHANGE_THRESHOLD = 50
12+
INCREASE_CHANGE_THRESHOLD = 85
13+
ACTION_INTERVAL = 3 # seconds
14+
15+
LAST_ACTION_TIME = 0
16+
17+
CUR_VALUE = 0
18+
19+
cc = ConsumerControl(usb_hid.devices)
20+
21+
encoder = rotaryio.IncrementalEncoder(board.ROTA, board.ROTB)
22+
switch = digitalio.DigitalInOut(board.SWITCH)
23+
switch.switch_to_input(pull=digitalio.Pull.DOWN)
24+
25+
switch_state = None
26+
last_position = encoder.position
27+
28+
29+
while True:
30+
now = time.monotonic()
31+
if (now > LAST_ACTION_TIME + ACTION_INTERVAL):
32+
print("Time for action")
33+
print(CUR_VALUE)
34+
35+
LAST_ACTION_TIME = now
36+
if CUR_VALUE < STAY_EVEN_CHANGE_THRESHOLD:
37+
cc.send(ConsumerControlCode.BRIGHTNESS_DECREMENT)
38+
print("brightness down")
39+
elif CUR_VALUE < INCREASE_CHANGE_THRESHOLD:
40+
print("stay even")
41+
else:
42+
print("brightness up")
43+
cc.send(ConsumerControlCode.BRIGHTNESS_INCREMENT)
44+
45+
CUR_VALUE = 0
46+
47+
48+
current_position = encoder.position
49+
position_change = int(current_position - last_position)
50+
51+
if position_change > 0:
52+
53+
for _ in range(position_change):
54+
CUR_VALUE += position_change
55+
56+
elif position_change < 0:
57+
for _ in range(-position_change):
58+
CUR_VALUE += int(math.fabs(position_change))
59+
60+
last_position = current_position
61+
if not switch.value and switch_state is None:
62+
switch_state = "pressed"
63+
if switch.value and switch_state == "pressed":
64+
print("switch pressed.")

0 commit comments

Comments
 (0)