Advertisement
Guest User

Untitled

a guest
Mar 27th, 2019
105
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None
  1. import serial;
  2. from psonic import *;
  3. from threading import Thread;
  4. import atexit;
  5. from pythonosc import osc_message_builder;
  6. from pythonosc import udp_client;
  7. ser = serial.Serial('/dev/ttyACM0',9600, timeout=1);
  8. s = 0;
  9. n = 0.0;
  10. run("""@osc_server ||= SonicPi::OSC::UDPServer.new(4559, use_decoder_cache: true)
  11. use_synth :sine
  12. set_sched_ahead_time! 0 #for short latency
  13. s = play 60, release: 0, sustain:100, amp:0.1, attack:0
  14. loop do
  15. a, b = sync "/osc/trigger/prophet"
  16. control s, note:a, amp:b
  17. end""");
  18. while True:
  19. try:
  20. st = ser.readline().decode('utf-8');
  21. inn=int(st);
  22. if(inn > s+5 or inn < s-5):
  23. s = inn;
  24. sender = udp_client.SimpleUDPClient('127.0.0.1', 4559)
  25. if(inn != 0 and inn < 1020):
  26. n = (inn/1020.0)*12.0;
  27. print(72-n);
  28. sender.send_message('/trigger/prophet', [(72-n), 1]);
  29. else:
  30. send_message('/trigger/prophet', [0, 0]);
  31. n = 0.0;
  32. except:
  33. print("no num");
Advertisement
RAW Paste Data Copied
Advertisement