adding rotary trinkey crank inital files
This commit is contained in:
parent
50f62d29aa
commit
3c12b36253
4 changed files with 152 additions and 0 deletions
|
|
@ -0,0 +1,88 @@
|
|||
shaft_cutout = 6.2 + 1.7;
|
||||
|
||||
Z_HEIGHT = 30;
|
||||
X_HEIGHT = 36;
|
||||
Y_HEIGHT = 38;
|
||||
THICKNESS = 1.5 * 2;
|
||||
|
||||
USB_CUTOUT_Z = 20;
|
||||
USB_CUTOUT_X = 17;
|
||||
USB_CUTOUT_Y = 40;
|
||||
|
||||
TAB_SIZE = 6;
|
||||
TAB_HEIGHT = 2;
|
||||
TAB_TOLERANCE = 0.1;
|
||||
|
||||
USB_WALL_OFFSET = 1;
|
||||
|
||||
/*
|
||||
difference(){
|
||||
cube([X_HEIGHT, Y_HEIGHT, Z_HEIGHT], center=true);
|
||||
translate([0,0,THICKNESS/2])
|
||||
cube([X_HEIGHT-THICKNESS, Y_HEIGHT-THICKNESS, Z_HEIGHT], center=true);
|
||||
|
||||
translate([10,-3,0])
|
||||
rotate([0,90,0])
|
||||
cylinder(r=shaft_cutout/2, h=40, center=true, $fn=30);
|
||||
|
||||
translate([X_HEIGHT/2 - USB_CUTOUT_X/2 - THICKNESS/2 - USB_WALL_OFFSET,20,0])
|
||||
cube([USB_CUTOUT_X, USB_CUTOUT_Y, USB_CUTOUT_Z], center=true);
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
translate([7.5,20.5 - 3,0])
|
||||
rotate([-90,0,-90])
|
||||
import("4964 Rotary Trinkey.stl");
|
||||
*/
|
||||
|
||||
module close_tab(){
|
||||
difference(){
|
||||
cube([TAB_SIZE,TAB_SIZE,TAB_HEIGHT], center=true);
|
||||
translate([1.5, 1.5, 0])
|
||||
cube([TAB_SIZE,TAB_SIZE,TAB_HEIGHT+1], center=true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module lid(){
|
||||
cube([X_HEIGHT, Y_HEIGHT, THICKNESS/2], center=true);
|
||||
|
||||
translate([
|
||||
-X_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
|
||||
-Y_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
|
||||
THICKNESS/4 + 2/2
|
||||
])
|
||||
close_tab();
|
||||
|
||||
translate([
|
||||
X_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
|
||||
Y_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
|
||||
THICKNESS/4 + 2/2
|
||||
])
|
||||
rotate([0,0,180])
|
||||
close_tab();
|
||||
|
||||
translate([
|
||||
X_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
|
||||
-Y_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
|
||||
THICKNESS/4 + 2/2
|
||||
])
|
||||
rotate([0,0,90])
|
||||
close_tab();
|
||||
|
||||
translate([
|
||||
-X_HEIGHT/2 + 6/2 + THICKNESS/2 + TAB_TOLERANCE,
|
||||
Y_HEIGHT/2 - 6/2 - THICKNESS/2 - TAB_TOLERANCE,
|
||||
THICKNESS/4 + 2/2
|
||||
])
|
||||
rotate([0,0,270])
|
||||
close_tab();
|
||||
}
|
||||
|
||||
translate([0,0,16])
|
||||
//rotate([0,180,0])
|
||||
lid();
|
||||
|
||||
//translate([0, Y_HEIGHT/2-1, 10])
|
||||
//cube([1,1,1], center=true);
|
||||
Binary file not shown.
Binary file not shown.
64
Rotary_Trinkey_Brightness_Crank/code.py
Normal file
64
Rotary_Trinkey_Brightness_Crank/code.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import time
|
||||
import board
|
||||
import digitalio
|
||||
import rotaryio
|
||||
import math
|
||||
import usb_hid
|
||||
from adafruit_hid.consumer_control import ConsumerControl
|
||||
from adafruit_hid.consumer_control_code import ConsumerControlCode
|
||||
|
||||
|
||||
STAY_EVEN_CHANGE_THRESHOLD = 50
|
||||
INCREASE_CHANGE_THRESHOLD = 85
|
||||
ACTION_INTERVAL = 3 # seconds
|
||||
|
||||
LAST_ACTION_TIME = 0
|
||||
|
||||
CUR_VALUE = 0
|
||||
|
||||
cc = ConsumerControl(usb_hid.devices)
|
||||
|
||||
encoder = rotaryio.IncrementalEncoder(board.ROTA, board.ROTB)
|
||||
switch = digitalio.DigitalInOut(board.SWITCH)
|
||||
switch.switch_to_input(pull=digitalio.Pull.DOWN)
|
||||
|
||||
switch_state = None
|
||||
last_position = encoder.position
|
||||
|
||||
|
||||
while True:
|
||||
now = time.monotonic()
|
||||
if (now > LAST_ACTION_TIME + ACTION_INTERVAL):
|
||||
print("Time for action")
|
||||
print(CUR_VALUE)
|
||||
|
||||
LAST_ACTION_TIME = now
|
||||
if CUR_VALUE < STAY_EVEN_CHANGE_THRESHOLD:
|
||||
cc.send(ConsumerControlCode.BRIGHTNESS_DECREMENT)
|
||||
print("brightness down")
|
||||
elif CUR_VALUE < INCREASE_CHANGE_THRESHOLD:
|
||||
print("stay even")
|
||||
else:
|
||||
print("brightness up")
|
||||
cc.send(ConsumerControlCode.BRIGHTNESS_INCREMENT)
|
||||
|
||||
CUR_VALUE = 0
|
||||
|
||||
|
||||
current_position = encoder.position
|
||||
position_change = int(current_position - last_position)
|
||||
|
||||
if position_change > 0:
|
||||
|
||||
for _ in range(position_change):
|
||||
CUR_VALUE += position_change
|
||||
|
||||
elif position_change < 0:
|
||||
for _ in range(-position_change):
|
||||
CUR_VALUE += int(math.fabs(position_change))
|
||||
|
||||
last_position = current_position
|
||||
if not switch.value and switch_state is None:
|
||||
switch_state = "pressed"
|
||||
if switch.value and switch_state == "pressed":
|
||||
print("switch pressed.")
|
||||
Loading…
Reference in a new issue