Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import board
- import time
- import digitalio
- import math
- import array
- import audioio
- import neopixel
- import touchio
- from board import *
- length = 8000 // 440
- sine_wave = array.array("H", [0] * length)
- for i in range(length):
- sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
- speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
- speaker_enable.switch_to_output(value=True)
- pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
- touch = touchio.TouchIn(A0)
- touch1 = touchio.TouchIn(A1)
- touch2 = touchio.TouchIn(A2)
- touch3 = touchio.TouchIn(A3)
- touch4 = touchio.TouchIn(A4)
- touch5 = touchio.TouchIn(A5)
- touch6 = touchio.TouchIn(A6)
- touch7 = touchio.TouchIn(A7)
- sample = audioio.AudioOut(board.SPEAKER, sine_wave)
- while True:
- if touch.value:
- print('touched 1!')
- sample.frequency = 16000
- sample.play(loop=True)
- time.sleep(1)
- pixels.fill((20, 0, 0))
- pixels.write()
- else:
- pixels.fill((0, 0, 0))
- pixels.write()
- sample.stop()
- if touch1.value:
- print('touched 2!')
- pixels[0] = ((120, 0, 0))
- pixels[1] = ((0, 120, 0))
- pixels.write()
- else:
- pixels.fill((0, 0, 0))
- pixels.write()
- time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement