Format Screaming Cauldron
MODIFY
ScreamingCauldron/screamingCauldron.py
ScreamingCauldron/screamingCauldron.py
# Screaming Cauldron
# for Adafruit Industries Learning Guide
-from digitalio import DigitalInOut, Direction
-from analogio import AnalogIn
-import neopixel
-import board
import time
+import board
+import neopixel
+from analogio import AnalogIn
+from digitalio import DigitalInOut, Direction
+
led = DigitalInOut(board.D13) # on board red LED
led.direction = Direction.OUTPUT
@@ -24,27 +25,30 @@ pixels = neopixel.NeoPixel(neoPin, numPix, auto_write=0, brightness=.8)
pixels.fill((0, 0, 0,))
pixels.show()
-def getVoltage(pin):
+
+def get_voltage(pin):
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
# Figure out how 'wide' each range is
- leftSpan = leftMax - leftMin
- rightSpan = rightMax - rightMin
+ leftSpan = left_max - left_min
+ rightSpan = right_max - right_min
# 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.
- return int(rightMin + (valueScaled * rightSpan))
+ return int(right_min + (valueScaled * rightSpan))
+
while True:
distRaw = analog0in.value # read the raw sensor value
print("A0: %f" % distRaw) # write raw value to REPL
- distRedColor = remapRange(distRaw, 0, 64000, 0, 255)
- distGreenColor = remapRange(distRaw, 0, 64000, 200, 0)
- if(distRaw > 40000): # at about 4 inches, this goes off!
+ distRedColor = remap_range(distRaw, 0, 64000, 0, 255)
+ distGreenColor = remap_range(distRaw, 0, 64000, 200, 0)
+ if distRaw > 40000: # at about 4 inches, this goes off!
led.value = True
aFXPin.value = False
time.sleep(.35)

Format Screaming Cauldron