Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brightness #235

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ $RECYCLE.BIN/
.TemporaryItems
.Trashes
.VolumeIcon.icns
.vscode

# Directories potentially created on remote AFP share
.AppleDB
Expand Down
5 changes: 4 additions & 1 deletion python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
to control the leds connected to it.
"""

BRIGHTNESS = 1
"""Set between 0 and 1 to control LED brightness for pi,esp8266,and blinkstick"""

if DEVICE == 'esp8266':
UDP_IP = '192.168.0.150'
"""IP address of the ESP8266. Must match IP in ws2812_controller.ino"""
Expand All @@ -31,7 +34,7 @@
"""LED signal frequency in Hz (usually 800kHz)"""
LED_DMA = 5
"""DMA channel used for generating PWM signal (try 5)"""
BRIGHTNESS = 255
PI_BRIGHTNESS = 255 * BRIGHTNESS
"""Brightness of LED strip between 0 and 255"""
LED_INVERT = True
"""Set True if using an inverting logic level converter"""
Expand Down
16 changes: 8 additions & 8 deletions python/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import neopixel
strip = neopixel.Adafruit_NeoPixel(config.N_PIXELS, config.LED_PIN,
config.LED_FREQ_HZ, config.LED_DMA,
config.LED_INVERT, config.BRIGHTNESS)
config.LED_INVERT, config.PI_BRIGHTNESS)
strip.begin()
elif config.DEVICE == 'blinkstick':
from blinkstick import blinkstick
Expand Down Expand Up @@ -72,12 +72,12 @@ def _update_esp8266():
m = '' if _is_python_2 else []
for i in packet_indices:
if _is_python_2:
m += chr(i) + chr(p[0][i]) + chr(p[1][i]) + chr(p[2][i])
m += chr(i) + chr(int(p[0][i]*config.BRIGHTNESS)) + chr(int(p[1][i]*config.BRIGHTNESS)) + chr(int(p[2][i]*config.BRIGHTNESS))
else:
m.append(i) # Index of pixel to change
m.append(p[0][i]) # Pixel red value
m.append(p[1][i]) # Pixel green value
m.append(p[2][i]) # Pixel blue value
m.append(int(p[0][i]*config.BRIGHTNESS)) # Pixel red value
m.append(int(p[1][i]*config.BRIGHTNESS)) # Pixel green value
m.append(int(p[2][i]*config.BRIGHTNESS)) # Pixel blue value
m = m if _is_python_2 else bytes(m)
_sock.sendto(m, (config.UDP_IP, config.UDP_PORT))
_prev_pixels = np.copy(p)
Expand Down Expand Up @@ -119,9 +119,9 @@ def _update_blinkstick():
# Optional gamma correction
p = _gamma[pixels] if config.SOFTWARE_GAMMA_CORRECTION else np.copy(pixels)
# Read the rgb values
r = p[0][:].astype(int)
g = p[1][:].astype(int)
b = p[2][:].astype(int)
r = (config.BRIGHTNESS*p[0][:]).astype(int)
g = (config.BRIGHTNESS*p[1][:]).astype(int)
b = (config.BRIGHTNESS*p[2][:]).astype(int)

#create array in which we will store the led states
newstrip = [None]*(config.N_PIXELS*3)
Expand Down
15 changes: 15 additions & 0 deletions python/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ def freq_slider_change(tick):
freq_label.setText('Frequency range: {} - {} Hz'.format(
config.MIN_FREQUENCY,
config.MAX_FREQUENCY))
# Brightness label
bright_label = pg.LabelItem('')
# Brightness slider
def bright_slider_change(tick):
newBrightness = bright_slider.tickValue(0)
bright_label.setText('Brightness level: {:.0f}%'.format(newBrightness*100))
config.BRIGHTNESS = newBrightness
bright_slider = pg.TickSliderItem(orientation='bottom', allowAdd=True)
bright_slider.addTick(config.BRIGHTNESS, color='#16dbeb' , movable=True)
bright_slider.tickMoveFinished = bright_slider_change
bright_label.setText('Brightness: {:.0f}%'.format(bright_slider.tickValue(0)*100))
# Effect selection
active_color = '#16dbeb'
inactive_color = '#FFFFFF'
Expand Down Expand Up @@ -350,6 +361,10 @@ def spectrum_click(x):
layout.addItem(energy_label)
layout.addItem(scroll_label)
layout.addItem(spectrum_label)
layout.nextRow()
layout.addItem(bright_label, colspan=3)
layout.nextRow()
layout.addItem(bright_slider, colspan=3)
# Initialize LEDs
led.update()
# Start listening to live audio stream
Expand Down