Skip to content

Commit cbe993e

Browse files
authored
Add Binary Counter script
1 parent 6b7d751 commit cbe993e

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

software/contrib/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ Smooth random voltages based on bezier curves. Inspired by the ADDAC507 Random B
2828
<i>Author: [chrisib](https://github.com/chrisib)</i>
2929
<br><i>Labels: Random</i>
3030

31+
### Binary Counter \[ [documentation](/software/contrib/binary_counter.md) | [script](/software/contrib/binary_counter.py) \]
32+
33+
A simple gate sequencer implemented using a 6-bit binary counter.
34+
35+
<i>Author: [chrisib](https://github.com/chrisib)</i>
36+
<br><i>Labels: gates, sequencer, binary</i>
37+
3138
### Bit Garden \[ [documentation](/software/contrib/bit_garden.md) | [script](/software/contrib/bit_garden.py) \]
3239

3340
Mirrors a gate/trigger input, with adjustable skip probability across channels.

software/contrib/binary_counter.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Binary Counter
2+
3+
Binary Counter is a simple gate sequencer that uses binary numbers to turn gates on & off.
4+
5+
Starting from zero, every time a gate is received on `din`, the value of the counter is
6+
incremented by `k`, and CV1-6 are set on/off according to the binary representation of the
7+
counter.
8+
9+
## I/O Mapping
10+
11+
| I/O | Usage
12+
|---------------|-------------------------------------------------------------------|
13+
| `din` | Input gate signal |
14+
| `ain` | CV input to control `k` |
15+
| `b1` | Manual gate signal |
16+
| `b2` | Reset `n` to zero |
17+
| `k1` | Control for `k` |
18+
| `k2` | Attenuator for `ain` |
19+
| `cv1` | Least significant bit output |
20+
| `cv2` | 2s-bit output |
21+
| `cv3` | 4s-bit output |
22+
| `cv4` | 8s-bit output |
23+
| `cv5` | 16s-bit output |
24+
| `cv6` | Most significant bit output |

software/contrib/binary_counter.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from europi import *
2+
from europi_script import EuroPiScript
3+
4+
5+
class BinaryCounter(EuroPiScript):
6+
MAX_N = (1 << NUM_CVS) - 1
7+
8+
def __init__(self):
9+
super().__init__()
10+
11+
self.n = 0
12+
self.k = int(
13+
(
14+
k1.percent() + k2.percent() * ain.percent()
15+
) * self.MAX_N
16+
)
17+
18+
self.gate_recvd = False
19+
20+
din.handler(self.on_gate_rise)
21+
din.handler_falling(self.on_gate_fall)
22+
b1.handler(self.on_gate_rise)
23+
b1.handler_falling(self.on_gate_fall)
24+
25+
b2.handler(self.reset)
26+
27+
def on_gate_rise(self):
28+
self.gate_recvd = True
29+
30+
def on_gate_fall(self):
31+
turn_off_all_cvs()
32+
33+
def reset(self):
34+
self.n = 0
35+
36+
def set_outputs(self):
37+
for i in range(NUM_CVS):
38+
if (self.n >> i) & 0x01:
39+
cvs[i].on()
40+
else:
41+
cvs[i].off()
42+
43+
def main(self):
44+
while True:
45+
self.k = int(
46+
(
47+
k1.percent() + k2.percent() * ain.percent()
48+
) * self.MAX_N
49+
)
50+
51+
if self.gate_recvd:
52+
self.set_outputs()
53+
self.n = (self.n + self.k) & self.MAX_N
54+
self.gate_recvd = False
55+
56+
oled.centre_text(f"""k = {self.k}
57+
{self.n:06b}""")
58+
59+
60+
if __name__ == "__main__":
61+
BinaryCounter().main()

software/contrib/menu.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
["Arpeggiator", "contrib.arp.Arpeggiator"],
2424
["Bernoulli Gates", "contrib.bernoulli_gates.BernoulliGates"],
2525
["Bezier Curves", "contrib.bezier.Bezier"],
26+
["Binary Counter", "contrib.binary_counter.BinaryCounter"],
2627
["Bit Garden", "contrib.bit_garden.BitGarden"],
2728
["Clock Modifier", "contrib.clock_mod.ClockModifier"],
2829
["Coin Toss", "contrib.coin_toss.CoinToss"],

0 commit comments

Comments
 (0)