Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import time
  4.  
  5. import pigpio
  6.  
  7. GPIO=[4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
  8.  
  9. NGPIO = len(GPIO)
  10.  
  11. cb = [0]*NGPIO
  12. last = [0]*NGPIO
  13. now = [0]*NGPIO
  14.  
  15. pi = pigpio.pi()
  16.  
  17. for i in range(NGPIO):
  18. pi.set_PWM_frequency(GPIO[i], 100000) # set maximum frequency.
  19. pi.set_PWM_dutycycle(GPIO[i], 128) # square wave.
  20. cb[i] = pi.callback(GPIO[i])
  21. last[i] = 0
  22.  
  23. while True:
  24.  
  25. time.sleep(1.0)
  26. total = 0
  27. for i in range(NGPIO):
  28. now[i] = cb[i].tally()
  29. total = total + now[i] - last[i]
  30. last[i] = now[i]
  31. print(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement