I'm back with another issue. I've finished all my connections and everything works great.. but the LEDs. Both the barrel and dial LEDs are not working at all. I've checked all my connections and everything looks in order. And the hall effect sensor is working, which is a good sign since it is powered off the barrel strip. Any suggestions to look at?
Â

Yes I believe so. DPDT bat is clustered with the LED bat (3.3v) leads, which is then soldered to the amplifier's bat (VIN) output.
They are wired to BAT on the amplifier.
Yeah I'm at a loss. I charged the battery and checked the POT at they both worked fine. The LED code works but when I load the raygun code, they will not light up.
The only difference I see is in the brightness value. Try changing the brightness in my code, or charge the battery for a while. The code shouldn't be the issue. Try running an example that uses a potentiometer to eliminate that as the problem. Even if it was a problem, it shouldn't be the cause of the Dial LEDs not working. Those aren't controlled by the pot.
"""CircuitPython Essentials NeoPixel example"""
import time
import board
import neopixel
pixel_pin = board.D5
pixel_pin = board.D6
num_pixels = 21
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, 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.
if pos < 0 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
def color_chase(color, wait):
for i in range(num_pixels):
pixels[i] = color
time.sleep(wait)
pixels.show()
time.sleep(0.5)
def rainbow_cycle(wait):
for j in range(255):
for i in range(num_pixels):
rc_index = (i * 256 // num_pixels) + j
pixels[i] = wheel(rc_index & 255)
pixels.show()
time.sleep(wait)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
while True:
pixels.fill(RED)
pixels.show()
# Increase or decrease to change the speed of the solid color change.
time.sleep(1)
pixels.fill(GREEN)
pixels.show()
time.sleep(1)
pixels.fill(BLUE)
pixels.show()
time.sleep(1)
color_chase(RED, 0.1) # Increase the number to slow down the color chase
color_chase(YELLOW, 0.1)
color_chase(GREEN, 0.1)
color_chase(CYAN, 0.1)
color_chase(BLUE, 0.1)
color_chase(PURPLE, 0.1)
rainbow_cycle(0) # Increase the number to slow down the rainbow
Interesting, so they all work as advertised so no issues there.
When I load the code.py they do not respond or light up. Is it possible there is an issue with the potentiometer?
Or any issues you see with the code?
import time
import board
import neopixel
import math
import audioio
import audiocore
from audiocore import WaveFile
from audioio import AudioOut
import digitalio
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn, AnalogOut
bar_pin = board.D5
dial_pin = board.D6
bar_pixels = 15
dial_pixels = 6
RED = (255, 0, 0)
YELLOW = (255, 255, 0)
GREEN = (0, 255, 0)
phase = 0
barrel = neopixel.NeoPixel(bar_pin, bar_pixels, brightness=1.0, auto_write=False)
dial = neopixel.NeoPixel(dial_pin, dial_pixels, brightness=1.0, auto_write=False)
# Give power to D10 which powers the speaker amplifier
enable = digitalio.DigitalInOut(board.D10)
enable.direction = digitalio.Direction.OUTPUT
enable.value = True
# Set up audio channel/Open audio files and prep for playback
audio = audioio.AudioOut(board.A0)
startup = audiocore.WaveFile(open("Startup.wav", "rb"))
shoot = audiocore.WaveFile(open("RayGunPew.wav", "rb"))
empty = audiocore.WaveFile(open("Empty.wav", "rb"))
quote1 = audiocore.WaveFile(open("Dempsey_1.wav", "rb"))
quote2 = audiocore.WaveFile(open("Dempsey_2.wav", "rb"))
quote3 = audiocore.WaveFile(open("Dempsey_3.wav", "rb"))
reloadOpen = audiocore.WaveFile(open("Reload_Open.wav", "rb"))
reloadClose = audiocore.WaveFile(open("Reload_Close.wav", "rb"))
trigger = DigitalInOut(board.D11)
trigger.direction = Direction.INPUT
trigger.pull = Pull.UP
sensor = DigitalInOut(board.D12)
sensor.direction = Direction.INPUT
sensor.pull = Pull.UP
pot_read = AnalogIn(board.A2)
barrel_open = False
hallstate = barrel_open
trigger_count = 0
ct = 0
check = time.monotonic()
last_check = check
last_val = 0
pause = 0.05
def get_color(pos):
if (pos < 0):
barrel.fill(0, 0, 0)
if (pos > 255):
barrel.fill(0, 0, 0)
if (pos < 85):
barrel.fill((int(255 - pos*3), 0, int(pos*3)))
elif (pos < 170):
pos -= 85
barrel.fill((0, int(pos*3), int(255 - pos*3)))
else:
pos -= 170
barrel.fill((int(pos * 3), int(255 - (pos*3)), 0))
barrel.show()
def get_mode(mode):
if mode <= 100:
barrel.fill((15, 100, 175))
barrel.show()
elif mode > 100 and mode <= 200:
barrel.fill((0, 255, 0))
barrel.show()
elif mode > 200 and mode <= 300:
barrel.fill((255, 0, 0))
barrel.show()
elif mode > 300 and mode <= 400:
blue_wave()
else:
white_wave()
def blue_wave():
for p in range(bar_pixels):
BLUE = int(abs(math.sin((p - phase)*3.14 / 18) * 235))+15
barrel[p] = (0, 0, BLUE)
barrel.show()
def white_wave():
for p in range(bar_pixels):
WHITE = int(abs(math.sin((p - phase)*3.14 / 18) * 175))+15
barrel[p] = (WHITE, WHITE, WHITE)
barrel.show()
def dial_disp():
dial[0] = RED
dial[1] = YELLOW
dial[2] = GREEN
dial.show()
def bad_fire(i):
if i == 0:
audio.play(empty)
elif i == 1:
audio.play(quote1)
elif i == 2:
audio.play(quote2)
elif i == 3:
audio.play(quote3)
for i in range(155):
barrel.fill((i, i, i))
dial[0] = (i, 0, 0)
dial[1] = (i, i, 0)
dial[2] = (0, i, 0)
dial.show()
barrel.show()
dial_disp()
audio.play(startup)
# Main loop
while True:
check = time.monotonic()
delta = abs(check - last_check)
if delta >= pause:
reading = pot_read.value
val = int((reading * 255) / 65535)
get_color(val)
phase += 1
last_check = check
last_hallstate = hallstate
hallstate = sensor.value
# If trigger is pulled while the barrel is closed
if not trigger.value and not sensor.value and not audio.playing:
if trigger_count < 20:
audio.play(shoot)
elif ct < 4:
bad_fire(ct)
ct += 1
else:
ct = 0
trigger_count += 1
elif hallstate and hallstate != last_hallstate:
audio.play(reloadOpen)
elif not hallstate and hallstate != last_hallstate:
trigger_count = 0
audio.play(reloadClose)
Usually the issue is arrow direction. Make sure the signal flow is in the right direction.
Since the LEDs are receiving V and GND, the problem most likely has to do with signal.
I recommend running an LED example code and making sure you can get the LEDs to work on their own. Once you know that the LEDs are working, you should be able to get them running with the ray gun code.