forked from monome/bowery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockdiv.lua
More file actions
34 lines (30 loc) · 746 Bytes
/
Copy pathclockdiv.lua
File metadata and controls
34 lines (30 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
--- clock divider
-- in1: clock input
-- in2: division selector (see divs)
-- out1-4: divided outputs
-- choose your clock divisions
divs = { {5,7,11,13} -- -5V
, {3,5,7,11}
, {2,3,5,7} -- 0V
, {2,4,8,16}
, {4,8,16,32} -- +5V
}
-- private vars
count = {1,1,1,1}
function init()
input[1].mode('change')
input[2].mode('none')
for n=1,4 do
output[n].slew = 0.001
end
end
input[1].change = function(s)
sel = math.floor(input[2].volts/2 + 3.5)
if sel > 5 then sel = 5 elseif sel < 1 then sel = 1 end
if s then
for n=1,4 do
count[n] = (count[n] % divs[sel][n])+1
output[n].volts = count[n] <= (divs[sel][n]/2) and 5 or 0
end
end
end