Advertisement
cymplecy

midi switch

Feb 13th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import time
  3. import pigpio # http://abyz.co.uk/rpi/pigpio/
  4. GPIO=4
  5.  
  6. SWITCH1 = 17 #(P11)
  7.  
  8. pi = pigpio.pi()                 # Connect to local Pi.
  9. pi.set_mode(GPIO, pigpio.OUTPUT) # Set GPIO as an output.
  10.  
  11. pi.set_mode(17, pigpio.INPUT)   #Set Pin 11 as input
  12. pi.set_pull_up_down(17, pigpio.PUD_UP)  #with pull-up
  13.  
  14. pi.wave_add_new()                # Clear any leftover data.
  15. pi.wave_add_serial(GPIO, 31250, chr(0x90)+chr(0x43)+chr(0x40))
  16. wid = pi.wave_create()           # Create wave from added data, get id.
  17.  
  18. while pi.read(17) == 1: #Wait while switch is not pressed
  19.     time.sleep(0.1)
  20.    
  21. for i in range(1):
  22.    pi.wave_send_once(wid)        # Transmit wave data.
  23.    while pi.wave_tx_busy():      # Wait for wave end, then repeat.
  24.       time.sleep(0.01)
  25. pi.wave_delete(wid)              # Delete wave to release used resources.
  26. pi.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement