Add files via upload

This commit is contained in:
mikeysklar 2017-12-26 14:50:40 -08:00 committed by GitHub
parent e970cfcde2
commit 181c51ab2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,18 +5,19 @@
# and output tone to GPIO #0 (digital 0)
import board
import pulseio
import analogio
import time
import neopixel
import simpleio
# Initialize input/output pins
photocell_pin = board.A1# cds photocell connected to this ANALOG pin
photocell_pin = board.A1 # cds photocell connected to this ANALOG pin
speaker_pin = board.D0 # speaker is connected to this DIGITAL pin
pixpin = board.D1 # pin where NeoPixels are connected
scale = 0.03 # change this to adjust tone scale
numpix = 10 # number of neopixels`
darkness_min = (2**16 / 2) # more dark than light > 32k out of 64k
photocell = analogio.AnalogIn(photocell_pin)
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.4)
# this section is Close Encounters Sounds
toned = 294
@ -25,70 +26,59 @@ tonec = 262
toneC = 130
toneg = 392
photocell = analogio.AnalogIn(photocell_pin)
pwm = pulseio.PWMOut(speaker_pin, variable_frequency=True, duty_cycle=0)
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.4)
# Read photocell analog pin and convert voltage to frequency
def beep(tone_freq):
pwm.frequency = tone_freq
pwm.duty_cycle = 32767 # 50% duty cycle
time.sleep(1) # Play for 1 second
pwm.duty_cycle = 0 # Stop playing
def alien():
strip[8] = (255, 255, 0) # yellow front
strip[3] = (255, 255, 0) # yellow back
beep(toned)
strip[8] = (255, 255, 0) # yellow front
strip[3] = (255, 255, 0) # yellow back
simpleio.tone(speaker_pin, toned, 1) # play tone for 1 second
time.sleep(.025)
strip[8] = (0, 0, 0) # clear front
strip[3] = (0, 0, 0) # clear back
strip[8] = (0, 0, 0) # clear front
strip[3] = (0, 0, 0) # clear back
time.sleep(.025)
strip[7] = (255, 0, 255) # pink front
strip[2] = (255, 0, 255) # pink back
beep(tonee)
strip[7] = (255, 0, 255) # pink front
strip[2] = (255, 0, 255) # pink back
simpleio.tone(speaker_pin, tonee, 1) # play tone for 1 second
time.sleep(.025)
strip[7] = (0, 0, 0) # clear front
strip[2] = (0, 0, 0) # clear back
strip[7] = (0, 0, 0) # clear front
strip[2] = (0, 0, 0) # clear back
time.sleep(.025)
strip[4] = (128, 255, 0) # green front
strip[9] = (128, 255, 0) # green back
beep(tonec)
strip[4] = (128, 255, 0) # green front
strip[9] = (128, 255, 0) # green back
simpleio.tone(speaker_pin, tonec, 1) # play tone for 1 second
time.sleep(.025)
strip[4] = (0, 0, 0) # clear front
strip[9] = (0, 0, 0) # clear back
strip[4] = (0, 0, 0) # clear front
strip[9] = (0, 0, 0) # clear back
time.sleep(.025)
strip[5] = (0, 0, 255) # blue front
strip[0] = (0, 0, 255) # blue back
beep(toneC)
strip[5] = (0, 0, 255) # blue front
strip[0] = (0, 0, 255) # blue back
simpleio.tone(speaker_pin, toneC, 1) # play tone for 1 second
time.sleep(.075)
strip[5] = (0, 0, 0) # clear front
strip[0] = (0, 0, 0) # clear back
strip[5] = (0, 0, 0) # clear front
strip[0] = (0, 0, 0) # clear back
time.sleep(.1)
strip[6] = (255, 0, 0) # red front
strip[1] = (255, 0, 0) # red back
beep(toneg)
strip[6] = (255, 0, 0) # red front
strip[1] = (255, 0, 0) # red back
simpleio.tone(speaker_pin, toneg, 1) # play tone for 1 second
time.sleep(.1)
strip[6] = (0, 0, 0) # clear front
strip[1] = (0, 0, 0) # clear back
strip[6] = (0, 0, 0) # clear front
strip[1] = (0, 0, 0) # clear back
time.sleep(.1)