Working version
This commit is contained in:
parent
db0d17f8c5
commit
08f0e448cc
5 changed files with 63 additions and 34 deletions
|
|
@ -57,7 +57,7 @@ def npcycle():
|
|||
np[j] = (0, 0, 0)
|
||||
np[i % lednumber] = (126, 20, 126)
|
||||
np.write()
|
||||
time.sleep_ms(150)
|
||||
time.sleep_ms(15)
|
||||
|
||||
npcolor(0,0,0)
|
||||
npcycle()
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import sys, time
|
|||
import socket
|
||||
from uosc.server import run_server, split_oscstr, parse_message, parse_bundle
|
||||
from uosc.client import send
|
||||
from uosc.client import Client
|
||||
from machine import Pin
|
||||
import mynetconf as netconf
|
||||
import machine, neopixel
|
||||
|
|
@ -21,13 +22,15 @@ MAX_DGRAM_SIZE = 1472
|
|||
OSCport = 9001
|
||||
|
||||
ledpin = Pin(2, Pin.OUT)
|
||||
stripin = Pin(14, Pin.OUT)
|
||||
ESPledstate = False
|
||||
n = 8
|
||||
|
||||
stripin = Pin(14, Pin.OUT)
|
||||
|
||||
n = 144
|
||||
np = neopixel.NeoPixel(stripin, n)
|
||||
motherip = "192.168.2.104"
|
||||
motherosc = Client(motherip, 9002)
|
||||
|
||||
leftnote = 36
|
||||
|
||||
def ESPledon():
|
||||
global ESPledstate
|
||||
|
|
@ -43,6 +46,28 @@ def ESPledoff():
|
|||
|
||||
ESPledoff()
|
||||
|
||||
|
||||
def noteledon(notenumber, velocity, r = 128, g=0 , b=64 ):
|
||||
|
||||
if notenumber > leftnote-1:
|
||||
|
||||
np[int((notenumber-leftnote)*2)] = (velocity*2,g,b)
|
||||
np[int((notenumber-leftnote)*2)+1] = (velocity*2,g,b)
|
||||
np.write()
|
||||
motherosc.send('/noteledon', notenumber)
|
||||
else:
|
||||
motherosc.send('/notetoolow', notenumber)
|
||||
|
||||
def noteledoff(notenumber):
|
||||
|
||||
if notenumber > leftnote-1:
|
||||
np[int((notenumber-leftnote)*2)] = (0, 0, 0)
|
||||
np[int((notenumber-leftnote)*2)+1] = (0, 0, 0)
|
||||
np.write()
|
||||
motherosc.send('/noteledoff', notenumber)
|
||||
else:
|
||||
motherosc.send('/notetoolow', notenumber)
|
||||
|
||||
def npcycle():
|
||||
|
||||
for i in range(2 * n):
|
||||
|
|
@ -50,7 +75,7 @@ def npcycle():
|
|||
np[j] = (0, 0, 0)
|
||||
np[i % n] = (126, 20, 126)
|
||||
np.write()
|
||||
time.sleep_ms(150)
|
||||
time.sleep_ms(15)
|
||||
|
||||
'''
|
||||
def npcycle2(r, g, b, wait):
|
||||
|
|
@ -90,32 +115,33 @@ def npbounce():
|
|||
|
||||
def OSCHandler(t, msg):
|
||||
|
||||
print()
|
||||
#print()
|
||||
print("OSCHandler")
|
||||
'''
|
||||
print("OSC address:", msg[0]) # /on
|
||||
print("Type tags:", msg[1]) # 'i'
|
||||
print("Arguments:", msg[2]) # (1,)
|
||||
print()
|
||||
'''
|
||||
|
||||
# /noteon midichannel note velocity
|
||||
if msg[0] == "/noteon":
|
||||
print("NOTEON channel", msg[2][0], "note",msg[2][1], "velocity", msg[2][2])
|
||||
np[int(msg[2][1]%n)] = (255, 0, 153)
|
||||
np.write()
|
||||
|
||||
print("ESP : NOTEON channel", msg[2][0], "note",msg[2][1], "velocity", msg[2][2])
|
||||
noteledon(int(msg[2][1]), int(msg[2][2]))
|
||||
#np[int(msg[2][1]%n)] = (255, 0, 153)
|
||||
#np.write()
|
||||
|
||||
# /noteoff midichannel note
|
||||
|
||||
if msg[0] =='/noteoff':
|
||||
print("NOTEOFF channel", msg[2][0], "note",msg[2][1])
|
||||
np[int(msg[2][1]%n)] = (0, 0, 0)
|
||||
np.write()
|
||||
print("ESP : NOTEOFF channel", msg[2][0], "note",msg[2][1])
|
||||
noteledoff(int(msg[2][1]))
|
||||
#np.write()
|
||||
|
||||
|
||||
def handle_rawosc(data, src, strict=False):
|
||||
try:
|
||||
head, _ = split_oscstr(data, 0)
|
||||
if __debug__: print("head", head)
|
||||
#if __debug__: print("head", head)
|
||||
|
||||
if head.startswith('/'):
|
||||
messages = [(-1, parse_message(data, strict))]
|
||||
|
|
@ -128,11 +154,12 @@ def handle_rawosc(data, src, strict=False):
|
|||
|
||||
try:
|
||||
for timetag, (oscaddr, tags, args) in messages:
|
||||
'''
|
||||
if __debug__:
|
||||
print("OSC address: %s" % oscaddr)
|
||||
print("OSC type tags: %r" % tags)
|
||||
print("OSC arguments: %r" % (args,))
|
||||
|
||||
'''
|
||||
print("Dispatching", timetag, (oscaddr, tags, args, src))
|
||||
OSCHandler(timetag, (oscaddr, tags, args, src))
|
||||
|
||||
|
|
@ -142,12 +169,14 @@ def handle_rawosc(data, src, strict=False):
|
|||
|
||||
|
||||
def run_server(saddr, port):
|
||||
|
||||
motherosc.send('/runningserver', 1)
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
if __debug__: print("Created OSC UDP server socket.")
|
||||
|
||||
sock.bind((saddr, port))
|
||||
print("Listening for OSC messages on %s:%i.", saddr, port)
|
||||
print("Listening for OSC messages on", saddr, port)
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
|
|
|||
|
|
@ -10,3 +10,5 @@ print("in main IP :",ip)
|
|||
|
||||
from lserver import main
|
||||
main(ip)
|
||||
#from osctest import main
|
||||
#main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue