formatting cleanup
This commit is contained in:
parent
729d80b4f5
commit
892f2cfccf
1 changed files with 15 additions and 15 deletions
|
|
@ -1,34 +1,34 @@
|
||||||
# Screaming Cauldron
|
# Screaming Cauldron
|
||||||
# for Adafruit Industries Learning Guide
|
# for Adafruit Industries Learning Guide
|
||||||
|
|
||||||
from digitalio import DigitalInOut, Direction#, Pull
|
from digitalio import DigitalInOut, Direction
|
||||||
from analogio import AnalogIn
|
from analogio import AnalogIn
|
||||||
import neopixel
|
import neopixel
|
||||||
import board
|
import board
|
||||||
import time
|
import time
|
||||||
|
|
||||||
led = DigitalInOut(board.D13) #on board red LED
|
led = DigitalInOut(board.D13) # on board red LED
|
||||||
led.direction = Direction.OUTPUT
|
led.direction = Direction.OUTPUT
|
||||||
|
|
||||||
aFXPin = DigitalInOut(board.D2) #pin used to drive the AudioFX board
|
aFXPin = DigitalInOut(board.D2) # pin used to drive the AudioFX board
|
||||||
aFXPin.direction = Direction.OUTPUT
|
aFXPin.direction = Direction.OUTPUT
|
||||||
|
|
||||||
aFXPin.value = False #runs once at startup
|
aFXPin.value = False # runs once at startup
|
||||||
time.sleep(.1) #pause a moment
|
time.sleep(.1) # pause a moment
|
||||||
aFXPin.value = True #then turn it off
|
aFXPin.value = True # then turn it off
|
||||||
|
|
||||||
analog0in = AnalogIn(board.D1)
|
analog0in = AnalogIn(board.D1)
|
||||||
neoPin = board.D0 #pin int0 which the NeoPixels are plugged
|
neoPin = board.D0 # pin int0 which the NeoPixels are plugged
|
||||||
numPix = 30 #number of NeoPixels
|
numPix = 30 # number of NeoPixels
|
||||||
pixels = neopixel.NeoPixel(neoPin, numPix, auto_write=0, brightness=.8)
|
pixels = neopixel.NeoPixel(neoPin, numPix, auto_write=0, brightness=.8)
|
||||||
pixels.fill((0,0,0,))
|
pixels.fill((0, 0, 0,))
|
||||||
pixels.show()
|
pixels.show()
|
||||||
|
|
||||||
def getVoltage(pin):
|
def getVoltage(pin):
|
||||||
return (pin.value * 3.3) / 65536
|
return (pin.value * 3.3) / 65536
|
||||||
|
|
||||||
def remapRange(value, leftMin, leftMax, rightMin, rightMax):
|
def remapRange(value, leftMin, leftMax, rightMin, rightMax):
|
||||||
#this remaps a value from original (left) range to new (right) range
|
# this remaps a value from original (left) range to new (right) range
|
||||||
# Figure out how 'wide' each range is
|
# Figure out how 'wide' each range is
|
||||||
leftSpan = leftMax - leftMin
|
leftSpan = leftMax - leftMin
|
||||||
rightSpan = rightMax - rightMin
|
rightSpan = rightMax - rightMin
|
||||||
|
|
@ -40,11 +40,11 @@ def remapRange(value, leftMin, leftMax, rightMin, rightMax):
|
||||||
return int(rightMin + (valueScaled * rightSpan))
|
return int(rightMin + (valueScaled * rightSpan))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
distRaw = analog0in.value #read the raw sensor value
|
distRaw = analog0in.value # read the raw sensor value
|
||||||
print("A0: %f" % distRaw) #write raw value to REPL
|
print("A0: %f" % distRaw) # write raw value to REPL
|
||||||
distRedColor = remapRange(distRaw, 0, 64000, 0, 255)
|
distRedColor = remapRange(distRaw, 0, 64000, 0, 255)
|
||||||
distGreenColor = remapRange(distRaw, 0, 64000, 200, 0)
|
distGreenColor = remapRange(distRaw, 0, 64000, 200, 0)
|
||||||
if(distRaw>40000): #at about 4 inches, this goes off!
|
if(distRaw > 40000): # at about 4 inches, this goes off!
|
||||||
led.value = True
|
led.value = True
|
||||||
aFXPin.value = False
|
aFXPin.value = False
|
||||||
time.sleep(.35)
|
time.sleep(.35)
|
||||||
|
|
@ -53,7 +53,7 @@ while True:
|
||||||
led.value = False
|
led.value = False
|
||||||
aFXPin.value = True
|
aFXPin.value = True
|
||||||
|
|
||||||
#change pixel colors based on proximity
|
# change pixel colors based on proximity
|
||||||
|
|
||||||
print(distRedColor, distGreenColor, (distRedColor + distGreenColor))
|
print(distRedColor, distGreenColor, (distRedColor + distGreenColor))
|
||||||
pixels.fill((distRedColor, distGreenColor, 0))
|
pixels.fill((distRedColor, distGreenColor, 0))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue