Format Screaming Cauldron
This commit is contained in:
parent
7e7e396b97
commit
e2a22db1ed
1 changed files with 17 additions and 13 deletions
|
|
@ -1,12 +1,13 @@
|
||||||
# Screaming Cauldron
|
# Screaming Cauldron
|
||||||
# for Adafruit Industries Learning Guide
|
# for Adafruit Industries Learning Guide
|
||||||
|
|
||||||
from digitalio import DigitalInOut, Direction
|
|
||||||
from analogio import AnalogIn
|
|
||||||
import neopixel
|
|
||||||
import board
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import board
|
||||||
|
import neopixel
|
||||||
|
from analogio import AnalogIn
|
||||||
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
led = DigitalInOut(board.D13) # on board red LED
|
led = DigitalInOut(board.D13) # on board red LED
|
||||||
led.direction = Direction.OUTPUT
|
led.direction = Direction.OUTPUT
|
||||||
|
|
||||||
|
|
@ -24,27 +25,30 @@ 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 get_voltage(pin):
|
||||||
return (pin.value * 3.3) / 65536
|
return (pin.value * 3.3) / 65536
|
||||||
|
|
||||||
def remapRange(value, leftMin, leftMax, rightMin, rightMax):
|
|
||||||
|
def remap_range(value, left_min, left_max, right_min, right_max):
|
||||||
# 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 = left_max - left_min
|
||||||
rightSpan = rightMax - rightMin
|
rightSpan = right_max - right_min
|
||||||
|
|
||||||
# Convert the left range into a 0-1 range (int)
|
# Convert the left range into a 0-1 range (int)
|
||||||
valueScaled = int(value - leftMin) / int(leftSpan)
|
valueScaled = int(value - left_min) / int(leftSpan)
|
||||||
|
|
||||||
# Convert the 0-1 range into a value in the right range.
|
# Convert the 0-1 range into a value in the right range.
|
||||||
return int(rightMin + (valueScaled * rightSpan))
|
return int(right_min + (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 = remap_range(distRaw, 0, 64000, 0, 255)
|
||||||
distGreenColor = remapRange(distRaw, 0, 64000, 200, 0)
|
distGreenColor = remap_range(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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue