Autoformat Microphone flag
MODIFY
3D_Printed_LED_Microphone_Flag/3D_Printed_LED_Microphone_Flag.py
3D_Printed_LED_Microphone_Flag/3D_Printed_LED_Microphone_Flag.py
@@ -40,7 +40,8 @@ sample_window = .1 # Sample window for average level
peak_hang = 24 # Time of pause before peak dot falls
peak_fall = 4 # Rate of falling peak dot
input_floor = 10 # Lower range of analogRead input
-input_ceiling = 300 # Max range of analogRead input, the lower the value the more sensitive (1023 = max)
+# Max range of analogRead input, the lower the value the more sensitive (1023 = max)
+input_ceiling = 300
peak = 16 # Peak level of column; used for falling dots
sample = 0
@@ -50,6 +51,7 @@ dothangcount = 0 # Frame counter for holding peak dot
strip = neopixel.NeoPixel(led_pin, n_pixels, brightness=1, auto_write=False)
+
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
@@ -64,6 +66,7 @@ def wheel(pos):
pos -= 170
return (0, int(pos*3), int(255 - pos*3))
+
def remapRange(value, leftMin, leftMax, rightMin, rightMax):
# this remaps a value fromhere original (left) range to new (right) range
# Figure out how 'wide' each range is
@@ -76,6 +79,7 @@ def remapRange(value, leftMin, leftMax, rightMin, rightMax):
# Convert the 0-1 range into a value in the right range.
return int(rightMin + (valueScaled * rightSpan))
+
def fscale(originalmin, originalmax, newbegin, newend, inputvalue, curve):
originalrange = 0
newrange = 0
@@ -95,7 +99,8 @@ def fscale(originalmin, originalmax, newbegin, newend, inputvalue, curve):
# this seems more intuitive
# postive numbers give more weight to high end on output
curve = (curve * -.1)
- curve = pow(10, curve) # convert linear scale into lograthimic exponent for other pow function
+ # convert linear scale into lograthimic exponent for other pow function
+ curve = pow(10, curve)
# Check for out of range inputValues
if (inputvalue < originalmin):
@@ -125,10 +130,11 @@ def fscale(originalmin, originalmax, newbegin, newend, inputvalue, curve):
if (invflag == 0):
rangedvalue = (pow(normalizedcurval, curve) * newrange) + newbegin
else: # invert the ranges
- rangedvalue = newbegin - (pow(normalizedcurval, curve) * newrange);
+ rangedvalue = newbegin - (pow(normalizedcurval, curve) * newrange)
return(rangedvalue)
+
def drawLine(fromhere, to):
fromheretemp = 0
@@ -141,6 +147,7 @@ def drawLine(fromhere, to):
for i in range(fromhere, to):
strip[i] = (0, 0, 0)
+
while True:
time_start = time.monotonic() # current time used for sample window
@@ -153,7 +160,8 @@ while True:
# collect data for length of sample window (in seconds)
while ((time.monotonic() - time_start) < sample_window):
- sample = mic_pin.value / 64 # convert to arduino 10-bit [1024] fromhere 16-bit [65536]
+ # convert to arduino 10-bit [1024] fromhere 16-bit [65536]
+ sample = mic_pin.value / 64
if (sample < 1024): # toss out spurious readings

Autoformat Microphone flag