# Copyright 2024 Allen Synthesis
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from europi_script import EuroPiScript
from experimental.rtc import clock
A single gate or CV sequence
BASE_SEQUENCE_LENGTH = 16
def __init__(self, seed):
def regenerate(self, seed):
# randomize the length so the majority are 16, but we get some longer or shorter
length = self.BASE_SEQUENCE_LENGTH
pattern.append(random.random())
self.index = (self.index + 1) % len(self.pattern)
return (int(self.pattern[self.index] * 2) % 2) * europi_config.GATE_VOLTAGE
return self.pattern[self.index] * europi_config.MAX_OUTPUT_VOLTAGE
class DailyRandom(EuroPiScript):
Generates a set of pseudo-random gate and CV sequences every day
This script requires a realtime clock. Please refer to
experimental.clocks for supported clocks.
If no RTC is installed & configured, the default clock will be used,
but this will generate the same pattern every time the module is
Sequence(0) for cv in cvs
self.regenerate_sequences()
self.trigger_recvd = False
self.trigger_recvd = True
for i in range(len(cvs) // 2):
def regenerate_sequences(self):
datetime = clock.localnow()
second = datetime.second if datetime.second is not None else 0
weekday = datetime.weekday if datetime.weekday is not None else 1
# bit-shift the fields around to reduce collisions
self.BITMASKS[weekday - 1] ^ year ^ (month << 7) ^ day,
self.BITMASKS[weekday - 1] ^ year ^ (month << 6) ^ day ^ ~hour,
self.BITMASKS[weekday - 1] ^ year ^ (month << 7) ^ day ^ (hour << 6) ^ minute,
for i in range(len(self.sequences)):
self.sequences[i].regenerate(seeds[i % len(seeds)])
last_draw_at = clock.localnow()
oled.centre_text(str(last_draw_at).replace(" ", "\n"))
self.regenerate_sequences()
oled.centre_text(str(now).replace(" ", "\n"))
self.trigger_recvd = False
for i in range(len(self.sequences)):
cvs[i].voltage(self.sequences[i].gate_volts)
cvs[i].voltage(self.sequences[i].cv_volts)
if __name__ == "__main__":