When I run this script all the leds light up. Occasionally and intermittently the leds will switch back off and I can see the code is working as it should. Moments after all leds light up again. Can someone please help? Thanks!
Code:
import boardfrom rpi_ws281x import Adafruit_NeoPixel, Colorimport neopixelimport digitalioimport timepixel_pin = board.D10num_pixels = 40 # Number of LEDs in your stripbutton_left = digitalio.DigitalInOut(board.D3) # Button now on pin 3button_right = digitalio.DigitalInOut(board.D5) # Button now on pin 5button_left.switch_to_input(pull=digitalio.Pull.UP)button_right.switch_to_input(pull=digitalio.Pull.UP)# Create NeoPixel objectpixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=Fa$# Initial player positionplayer_pos = 0# Set all LEDs to black initiallypixels.fill((0, 0, 0)) # New call added herepixels.show() # Update display to reflect the initial black statedef move_pixel(direction): global player_pos player_pos = (player_pos + direction) % num_pixels # Wrap around at the en$ pixels.fill((0, 0, 0)) # Clear strip pixels[player_pos] = (255, 255, 255) # Set player pixel #pixels.showdef apply_physics(): global player_pos velocity = 2 # Adjust for desired sliding speed if player_pos > 0 and pixels[player_pos - 1] == (0, 0, 0): player_pos -= velocity if player_pos < num_pixels - 1 and pixels[player_pos + 1] == (0, 0, 0): player_pos += velocitywhile True: if not button_left.value: move_pixel(-1) # Move left time.sleep(0.05) # Delay for smoother movement elif not button_right.value: move_pixel(1) # Move right time.sleep(0.05) else: apply_physics() # Apply sliding physics pixels.show() # Update display
Statistics: Posted by Pizzadog — Tue Jan 23, 2024 1:00 am