-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import mido | ||
This comment has been minimized.
Sorry, something went wrong. |
||
import socket | ||
import time | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
HOST = 'x.x.x.x' | ||
This comment has been minimized.
Sorry, something went wrong. |
||
PORT = 12345 # Needs to match host | ||
|
||
def runit(): | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
with mido.open_output('IAC Driver Bus 1') as port: | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
note = 50 | ||
This comment has been minimized.
Sorry, something went wrong. |
||
port.send(mido.Message('note_on', note=note, velocity=50)) | ||
try: | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
s.connect((HOST, PORT)) | ||
while True: | ||
s.sendall(b'ping') | ||
This comment has been minimized.
Sorry, something went wrong. |
||
data_raw = s.recv(1024) | ||
data = int(data_raw.decode()) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
data_converted = int(data * 16000 / 511) - 8000 | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
# print("Converted value:", data_converted) | ||
pitch = data_converted | ||
This comment has been minimized.
Sorry, something went wrong. |
||
port.send(mido.Message('pitchwheel', pitch=pitch)) | ||
time.sleep(.05) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
except Exception: | ||
pass | ||
finally: | ||
port.send(mido.Message('note_off', note=note)) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Clean up files and ports that I probabaly forgot to close | ||
gc.collect() | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
|
||
import network | ||
import machine | ||
import socket | ||
import time | ||
from machine import ADC | ||
|
||
WLAN_SSID = '' | ||
WLAN_PW = '' | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# Connect to network | ||
This comment has been minimized.
Sorry, something went wrong. |
||
wlan = network.WLAN(network.STA_IF) | ||
wlan.active(True) | ||
if not wlan.isconnected(): | ||
print('connecting to network...') | ||
wlan.connect(WLAN_SSID, WLAN_PW) | ||
while not wlan.isconnected(): | ||
pass | ||
print(wlan.ifconfig()) | ||
device_ip = wlan.ifconfig()[0] | ||
print('Device IP:', device_ip) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
pin = machine.Pin(32, machine.Pin.IN) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
adc = ADC(pin) | ||
# Calibrate ADC | ||
# set 11dB input attenuation (voltage range roughly 0.0v - 3.6v) | ||
adc.atten(ADC.ATTN_11DB) | ||
# set 9 bit return values (returned range 0-511) | ||
adc.width(ADC.WIDTH_9BIT) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
|
||
HOST = device_ip | ||
PORT = 12345 # Needs to match client | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
try: | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
s.bind((HOST, PORT)) | ||
# Wait for new connections | ||
while True: | ||
s.listen(1) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
conn, addr = s.accept() | ||
print('Connected by', addr) | ||
# Wait for query | ||
while True: | ||
data = conn.recv(1024) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
if not data: | ||
break | ||
This comment has been minimized.
Sorry, something went wrong. |
||
conn.sendall(str(adc.read()).encode()) | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
||
except KeyboardInterrupt: | ||
pass # suppress keyboard interrupt traceback | ||
This comment has been minimized.
Sorry, something went wrong. |
||
finally: | ||
conn.close() | ||
s.close() | ||
This comment has been minimized.
Sorry, something went wrong.
grokpot
Author
Owner
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Docs | ||
* https://microbit-micropython.readthedocs.io/en/latest/devguide/repl.html | ||
|
||
## REPL Prompt | ||
* To enter: `screen /dev/cu.SLAB_USBtoUART 115200` | ||
* To exit, press Ctrl-A + k | ||
* Paste mode: Ctrl-E | ||
|
||
# midi converter in mac | ||
* https://mido.readthedocs.io/en/latest/ | ||
|
Really big fan of this library now.