Skip to content

Commit e2a22db

Browse files
committed
Format Screaming Cauldron
1 parent 7e7e396 commit e2a22db

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

ScreamingCauldron/screamingCauldron.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Screaming Cauldron
22
# for Adafruit Industries Learning Guide
33

4-
from digitalio import DigitalInOut, Direction
5-
from analogio import AnalogIn
6-
import neopixel
7-
import board
84
import time
95

6+
import board
7+
import neopixel
8+
from analogio import AnalogIn
9+
from digitalio import DigitalInOut, Direction
10+
1011
led = DigitalInOut(board.D13) # on board red LED
1112
led.direction = Direction.OUTPUT
1213

@@ -24,27 +25,30 @@
2425
pixels.fill((0, 0, 0,))
2526
pixels.show()
2627

27-
def getVoltage(pin):
28+
29+
def get_voltage(pin):
2830
return (pin.value * 3.3) / 65536
2931

30-
def remapRange(value, leftMin, leftMax, rightMin, rightMax):
32+
33+
def remap_range(value, left_min, left_max, right_min, right_max):
3134
# this remaps a value from original (left) range to new (right) range
3235
# Figure out how 'wide' each range is
33-
leftSpan = leftMax - leftMin
34-
rightSpan = rightMax - rightMin
36+
leftSpan = left_max - left_min
37+
rightSpan = right_max - right_min
3538

3639
# Convert the left range into a 0-1 range (int)
37-
valueScaled = int(value - leftMin) / int(leftSpan)
40+
valueScaled = int(value - left_min) / int(leftSpan)
3841

3942
# Convert the 0-1 range into a value in the right range.
40-
return int(rightMin + (valueScaled * rightSpan))
43+
return int(right_min + (valueScaled * rightSpan))
44+
4145

4246
while True:
4347
distRaw = analog0in.value # read the raw sensor value
4448
print("A0: %f" % distRaw) # write raw value to REPL
45-
distRedColor = remapRange(distRaw, 0, 64000, 0, 255)
46-
distGreenColor = remapRange(distRaw, 0, 64000, 200, 0)
47-
if(distRaw > 40000): # at about 4 inches, this goes off!
49+
distRedColor = remap_range(distRaw, 0, 64000, 0, 255)
50+
distGreenColor = remap_range(distRaw, 0, 64000, 200, 0)
51+
if distRaw > 40000: # at about 4 inches, this goes off!
4852
led.value = True
4953
aFXPin.value = False
5054
time.sleep(.35)

0 commit comments

Comments
 (0)