Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import board
  2. import time
  3. import digitalio
  4. import math
  5. import array
  6. import audioio
  7. import neopixel
  8. import touchio
  9. from board import *
  10.  
  11. length = 8000 // 440
  12. sine_wave = array.array("H", [0] * length)
  13. for i in range(length):
  14. sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
  15.  
  16. speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
  17. speaker_enable.switch_to_output(value=True)
  18. pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
  19. touch = touchio.TouchIn(A0)
  20. touch1 = touchio.TouchIn(A1)
  21. touch2 = touchio.TouchIn(A2)
  22. touch3 = touchio.TouchIn(A3)
  23. touch4 = touchio.TouchIn(A4)
  24. touch5 = touchio.TouchIn(A5)
  25. touch6 = touchio.TouchIn(A6)
  26. touch7 = touchio.TouchIn(A7)
  27. sample = audioio.AudioOut(board.SPEAKER, sine_wave)
  28.  
  29. while True:
  30. if touch.value:
  31. print('touched 1!')
  32. sample.frequency = 16000
  33. sample.play(loop=True)
  34. time.sleep(1)
  35. pixels.fill((20, 0, 0))
  36. pixels.write()
  37. else:
  38. pixels.fill((0, 0, 0))
  39. pixels.write()
  40. sample.stop()
  41. if touch1.value:
  42. print('touched 2!')
  43. pixels[0] = ((120, 0, 0))
  44. pixels[1] = ((0, 120, 0))
  45. pixels.write()
  46. else:
  47. pixels.fill((0, 0, 0))
  48. pixels.write()
  49. time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement