init
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
serial:/COM3
|
||||||
151
main.py
Normal file
151
main.py
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
from machine import Pin, ADC
|
||||||
|
from math import floor, ceil
|
||||||
|
from time import sleep_ms
|
||||||
|
|
||||||
|
led = Pin(25, Pin.OUT)
|
||||||
|
pot = ADC(0)
|
||||||
|
cv_left = ADC(1)
|
||||||
|
cv_right = ADC(2)
|
||||||
|
|
||||||
|
#pot_two = ADC(25)
|
||||||
|
# analog_one = ADC(32)
|
||||||
|
# analog_two = ADC(33)
|
||||||
|
|
||||||
|
def read_cv(target, interval = 100):
|
||||||
|
print(target.read_u16())
|
||||||
|
sleep_ms(interval)
|
||||||
|
|
||||||
|
def cv_to_led(target, interval = 100):
|
||||||
|
modulated_cv = round(target.read_u16() / 65535)
|
||||||
|
led.value(modulated_cv)
|
||||||
|
sleep_ms(interval)
|
||||||
|
|
||||||
|
def blink(sleep_duration = 1000):
|
||||||
|
# pot.read_u16() / 65535 approaches 0 as potentiometer approaches max,
|
||||||
|
# approaches 1 as potentiometer approaches min
|
||||||
|
|
||||||
|
modulated_sleep = max( \
|
||||||
|
floor(sleep_duration * (pot.read_u16()) / 65535), \
|
||||||
|
5 \
|
||||||
|
)
|
||||||
|
|
||||||
|
led.value(1)
|
||||||
|
sleep_ms(modulated_sleep)
|
||||||
|
|
||||||
|
modulated_sleep = max( \
|
||||||
|
floor(sleep_duration * (pot.read_u16()) / 66000), \
|
||||||
|
5 \
|
||||||
|
)
|
||||||
|
|
||||||
|
led.value(0)
|
||||||
|
sleep_ms(modulated_sleep)
|
||||||
|
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
# thank you rsta2 : https://github.com/rsta2/minisynth/blob/master/src/oscillator.cpp
|
||||||
|
sine_wave = [
|
||||||
|
0.00000000, 0.01745241, 0.03489950, 0.05233596, 0.06975647, 0.08715574, 0.10452846, 0.12186934,
|
||||||
|
0.13917310, 0.15643447, 0.17364818, 0.19080900, 0.20791169, 0.22495105, 0.24192190, 0.25881905,
|
||||||
|
0.27563736, 0.29237170, 0.30901699, 0.32556815, 0.34202014, 0.35836795, 0.37460659, 0.39073113,
|
||||||
|
0.40673664, 0.42261826, 0.43837115, 0.45399050, 0.46947156, 0.48480962, 0.50000000, 0.51503807,
|
||||||
|
0.52991926, 0.54463904, 0.55919290, 0.57357644, 0.58778525, 0.60181502, 0.61566148, 0.62932039,
|
||||||
|
0.64278761, 0.65605903, 0.66913061, 0.68199836, 0.69465837, 0.70710678, 0.71933980, 0.73135370,
|
||||||
|
0.74314483, 0.75470958, 0.76604444, 0.77714596, 0.78801075, 0.79863551, 0.80901699, 0.81915204,
|
||||||
|
0.82903757, 0.83867057, 0.84804810, 0.85716730, 0.86602540, 0.87461971, 0.88294759, 0.89100652,
|
||||||
|
0.89879405, 0.90630779, 0.91354546, 0.92050485, 0.92718385, 0.93358043, 0.93969262, 0.94551858,
|
||||||
|
0.95105652, 0.95630476, 0.96126170, 0.96592583, 0.97029573, 0.97437006, 0.97814760, 0.98162718,
|
||||||
|
0.98480775, 0.98768834, 0.99026807, 0.99254615, 0.99452190, 0.99619470, 0.99756405, 0.99862953,
|
||||||
|
0.99939083, 0.99984770, 1.00000000, 0.99984770, 0.99939083, 0.99862953, 0.99756405, 0.99619470,
|
||||||
|
0.99452190, 0.99254615, 0.99026807, 0.98768834, 0.98480775, 0.98162718, 0.97814760, 0.97437006,
|
||||||
|
0.97029573, 0.96592583, 0.96126170, 0.95630476, 0.95105652, 0.94551858, 0.93969262, 0.93358043,
|
||||||
|
0.92718385, 0.92050485, 0.91354546, 0.90630779, 0.89879405, 0.89100652, 0.88294759, 0.87461971,
|
||||||
|
0.86602540, 0.85716730, 0.84804810, 0.83867057, 0.82903757, 0.81915204, 0.80901699, 0.79863551,
|
||||||
|
0.78801075, 0.77714596, 0.76604444, 0.75470958, 0.74314483, 0.73135370, 0.71933980, 0.70710678,
|
||||||
|
0.69465837, 0.68199836, 0.66913061, 0.65605903, 0.64278761, 0.62932039, 0.61566148, 0.60181502,
|
||||||
|
0.58778525, 0.57357644, 0.55919290, 0.54463904, 0.52991926, 0.51503807, 0.50000000, 0.48480962,
|
||||||
|
0.46947156, 0.45399050, 0.43837115, 0.42261826, 0.40673664, 0.39073113, 0.37460659, 0.35836795,
|
||||||
|
0.34202014, 0.32556815, 0.30901699, 0.29237170, 0.27563736, 0.25881905, 0.24192190, 0.22495105,
|
||||||
|
0.20791169, 0.19080900, 0.17364818, 0.15643447, 0.13917310, 0.12186934, 0.10452846, 0.08715574,
|
||||||
|
0.06975647, 0.05233596, 0.03489950, 0.01745241, 0.00000000, -0.01745241, -0.03489950, -0.05233596,
|
||||||
|
-0.06975647, -0.08715574, -0.10452846, -0.12186934, -0.13917310, -0.15643447, -0.17364818, -0.19080900,
|
||||||
|
-0.20791169, -0.22495105, -0.24192190, -0.25881905, -0.27563736, -0.29237170, -0.30901699, -0.32556815,
|
||||||
|
-0.34202014, -0.35836795, -0.37460659, -0.39073113, -0.40673664, -0.42261826, -0.43837115, -0.45399050,
|
||||||
|
-0.46947156, -0.48480962, -0.50000000, -0.51503807, -0.52991926, -0.54463904, -0.55919290, -0.57357644,
|
||||||
|
-0.58778525, -0.60181502, -0.61566148, -0.62932039, -0.64278761, -0.65605903, -0.66913061, -0.68199836,
|
||||||
|
-0.69465837, -0.70710678, -0.71933980, -0.73135370, -0.74314483, -0.75470958, -0.76604444, -0.77714596,
|
||||||
|
-0.78801075, -0.79863551, -0.80901699, -0.81915204, -0.82903757, -0.83867057, -0.84804810, -0.85716730,
|
||||||
|
-0.86602540, -0.87461971, -0.88294759, -0.89100652, -0.89879405, -0.90630779, -0.91354546, -0.92050485,
|
||||||
|
-0.92718385, -0.93358043, -0.93969262, -0.94551858, -0.95105652, -0.95630476, -0.96126170, -0.96592583,
|
||||||
|
-0.97029573, -0.97437006, -0.97814760, -0.98162718, -0.98480775, -0.98768834, -0.99026807, -0.99254615,
|
||||||
|
-0.99452190, -0.99619470, -0.99756405, -0.99862953, -0.99939083, -0.99984770, -1.00000000, -0.99984770,
|
||||||
|
-0.99939083, -0.99862953, -0.99756405, -0.99619470, -0.99452190, -0.99254615, -0.99026807, -0.98768834,
|
||||||
|
-0.98480775, -0.98162718, -0.97814760, -0.97437006, -0.97029573, -0.96592583, -0.96126170, -0.95630476,
|
||||||
|
-0.95105652, -0.94551858, -0.93969262, -0.93358043, -0.92718385, -0.92050485, -0.91354546, -0.90630779,
|
||||||
|
-0.89879405, -0.89100652, -0.88294759, -0.87461971, -0.86602540, -0.85716730, -0.84804810, -0.83867057,
|
||||||
|
-0.82903757, -0.81915204, -0.80901699, -0.79863551, -0.78801075, -0.77714596, -0.76604444, -0.75470958,
|
||||||
|
-0.74314483, -0.73135370, -0.71933980, -0.70710678, -0.69465837, -0.68199836, -0.66913061, -0.65605903,
|
||||||
|
-0.64278761, -0.62932039, -0.61566148, -0.60181502, -0.58778525, -0.57357644, -0.55919290, -0.54463904,
|
||||||
|
-0.52991926, -0.51503807, -0.50000000, -0.48480962, -0.46947156, -0.45399050, -0.43837115, -0.42261826,
|
||||||
|
-0.40673664, -0.39073113, -0.37460659, -0.35836795, -0.34202014, -0.32556815, -0.30901699, -0.29237170,
|
||||||
|
-0.27563736, -0.25881905, -0.24192190, -0.22495105, -0.20791169, -0.19080900, -0.17364818, -0.15643447,
|
||||||
|
-0.13917310, -0.12186934, -0.10452846, -0.08715574, -0.06975647, -0.05233596, -0.03489950, -0.01745241
|
||||||
|
]
|
||||||
|
|
||||||
|
ONE_HERTZ = len(sine_wave) / 1000
|
||||||
|
|
||||||
|
class Oscillator:
|
||||||
|
def __init__(self, tick_interval_ms = 35, current_tick = 0) -> None:
|
||||||
|
self.tick_interval_ms = ceil(tick_interval_ms)
|
||||||
|
self.current_tick = current_tick
|
||||||
|
|
||||||
|
def step(self):
|
||||||
|
print(pot.read_u16())
|
||||||
|
|
||||||
|
current_step = sine_wave[self.current_tick]
|
||||||
|
self.current_tick = self.current_tick + 1 if self.current_tick + 1 < len(sine_wave) else 0
|
||||||
|
sleep_ms(self.tick_interval_ms)
|
||||||
|
return current_step
|
||||||
|
|
||||||
|
def out(self, cb):
|
||||||
|
current_step = sine_wave[self.current_tick]
|
||||||
|
self.current_tick = self.current_tick + 1 if self.current_tick + 1 < len(sine_wave) else 0
|
||||||
|
|
||||||
|
sleep_ms(ceil(self.tick_interval_ms))
|
||||||
|
return self.out(cb)
|
||||||
|
|
||||||
|
class DigitalOutput:
|
||||||
|
def __init__(self, POS_PIN, NEG_PIN):
|
||||||
|
self.POS_OUT = Pin(POS_PIN, Pin.OUT)
|
||||||
|
self.NEG_OUT = Pin(NEG_PIN, Pin.OUT)
|
||||||
|
|
||||||
|
def simulate(self, data: float):
|
||||||
|
if (data >= 0):
|
||||||
|
print(data)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def send(self, data: float, ):
|
||||||
|
if (data >= 0):
|
||||||
|
self.POS_OUT.value(data)
|
||||||
|
else:
|
||||||
|
self.NEG_OUT.value(data * -1)
|
||||||
|
|
||||||
|
def get_hz(target: int):
|
||||||
|
return len(sine_wave) / (target * 1000)
|
||||||
|
|
||||||
|
osc = Oscillator(get_hz(2))
|
||||||
|
out_one = DigitalOutput(19, 20)
|
||||||
|
|
||||||
|
print(Pin(16, Pin.IN).value())
|
||||||
|
|
||||||
|
def main():
|
||||||
|
pass
|
||||||
|
# while True:
|
||||||
|
# out_one.send(osc.step())
|
||||||
|
# print(osc.osc_out())
|
||||||
|
# blink()
|
||||||
|
# read_cv(cv_right, 35)
|
||||||
|
# cv_to_led(cv_right, 35)
|
||||||
|
|
||||||
|
# led.value(0)
|
||||||
10
pymakr.conf
Normal file
10
pymakr.conf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"py_ignore": [
|
||||||
|
".vscode",
|
||||||
|
".gitignore",
|
||||||
|
".git",
|
||||||
|
"env",
|
||||||
|
"venv"
|
||||||
|
],
|
||||||
|
"name": "picosynth"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user