Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Feather M4 Express with propmaker wing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather M4 Express with propmaker wing

by dman80601 on Wed Mar 18, 2020 8:15 pm

window lighting code.txt
(3.3 KiB) Downloaded 3 times
I'm a stained glass artist who is trying to use an Adafruit M4 express with the feather propmaker wing, 150 cool white Dotstar LEDs (5M at 30/M), 128 UV neopixels (4 1M strips), a 4 ohm 3W speaker (HIBOX3070-K), a 16mm momentary push button, and an Adafruit 5V 10A power supply.

What I'm trying to do is make a light box incorporating a stained glass window I made. I want 5 modes;
1st = everything off.
2nd = White dotstars on
3rd = White dotstars flash randomly
4th = UV neopixels on
5th = White Dotstars progressively light the window as a audio file plays, and at end the brightness increases.

I have gotten the code to the point where the code checker (MU) is not finding any issues BUT nothing is working at this point.
I know something is wrong but this is my first project and I don't know how to move on from where I'm at to working code.
The current audio file is not the final. I will need to either figure out how to compress the audio file I want or figure out how to add and SD card.
The audio file that I want to use is 12.2MB it plays for 6 minutes 41 seconds. That is why the sleep times are what they are.

I could really use some professional help, Thank you.

The code is:

Code: Select all | TOGGLE FULL SIZE
import time
import random
import audioio
import board
import neopixel
import adafruit_dotstar as dotstar
import digitalio

enable = digitalio.DigitalInOut(board.D10)
enable.direction = digitalio.Direction.OUTPUT
enable.value = True

# using adafruit feather M4 and propmaker wing
# using board led as inicator light
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

# Using a DotStar Digital LED Strip with 30 LEDs connected to hardware SPI
dots = dotstar.DotStar(board.SCK, board.MOSI, 150, brightness=0.1,
                       auto_write=False)

# Using 4 neopixel UV LED Strips with 32 LEDs connected to board Neopixel port
pixels = neopixel.NeoPixel(board.D5, 128, brightness=0.1, auto_write=False)

pixels.fill = (0, 0, 0)
dots.fill = (0, 0, 0)

def random_color():
    return random.randrange((0) or (255))

switch = digitalio.DigitalInOut(board.A3)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP

counter = 0

debounceTime = 0.2

wave_file = open("StreetChicken.wav", "rb")
wave = audioio.WaveFile(wave_file)
audio = audioio.AudioOut(board.A0)

# MAIN LOOP
n_pixels = len(pixels)
n_dots = len(dots)

while True:
    if switch.value is True:
        led.value = True
        pixels.fill = (0, 0, 0)  # turn all neopixels off
        pixels.show()
        dots.fill = (0, 0, 0)
        dots.show()
        counter += 1  # increase the counter by 1
        time.sleep(debounceTime)

    elif counter == 0:
        led.value = True
        time.sleep(0.1)

    elif counter == 1:
        for dot in range(n_dots):
            dots[dot] = (255, 255, 255)
            dots.show()
            time.sleep(0.1)

    elif counter == 2:
        for dot in range(n_dots):
            dots[dot] = (random_color(), random_color(), random_color())
            dots.show()
            time.sleep(0.25)

    elif counter == 3:
        for pixel in range(n_pixels):
            pixels[pixel] = (255, 255, 255)
            pixels.show()
            time.sleep(0.1)

    elif counter == 4:
        audio.play(wave)
        while audio.playing:
            pass

        dot[1: 15] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[16: 30] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[31: 45] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[46: 60] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[61: 75] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[76: 90] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[91: 105] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[105: 120] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[121: 135] = (255, 255, 255)
        dots.show()
        time.sleep(34.1)
        dot[dots] = (255, 255, 255)
        dots.show()
        time.sleep(15)
        dots(brightness=0.5)
        time.sleep(15)
        dots(brightness=1)
        time.sleep(15)
        dots(brightness=0.2)
        time.sleep(0.1)

    elif counter > 4:  # if counter goes above 4 set back to 0
        counter == 0

    else:
        led.value = False

print("counter ", counter)

dman80601
 
Posts: 3
Joined: Mon Mar 16, 2020 8:48 pm

Re: Feather M4 Express with propmaker wing

by dastels on Wed Mar 18, 2020 8:38 pm

So each time you push the button, you want to advance to the next mode?

So, by default when the button isn't pressed, the switch input is high (reflected by the use of Pull.UP). When the button is pushed the input goes False (the button is wired between the input and ground).

I mention that since you have
Code: Select all | TOGGLE FULL SIZE
if switch.value is True:


I assume that's checking for the switch to be pushed, if so it should be changed to:
Code: Select all | TOGGLE FULL SIZE
if switch.value is False:


That change will make a huge difference to the operation of the code. Give that a try and let us know how it goes.

Dave

dastels
 
Posts: 3102
Joined: Tue Oct 20, 2015 3:22 pm

Re: Feather M4 Express with propmaker wing

by dman80601 on Wed Mar 18, 2020 9:37 pm

I just tried changing the statement to False and no change :( I also tried independently changing to PULL.DOWN with both false and true stements in place and still no change.

dman80601
 
Posts: 3
Joined: Mon Mar 16, 2020 8:48 pm

Re: Feather M4 Express with propmaker wing

by dastels on Thu Mar 19, 2020 10:34 am

You need Pull.Up, and checking for a low on the input.

You might need to debounce the input as well. Have a look at https://learn.adafruit.com/debouncer-library-python-circuitpython-buttons-sensors

Dave

dastels
 
Posts: 3102
Joined: Tue Oct 20, 2015 3:22 pm

Re: Feather M4 Express with propmaker wing

by dman80601 on Fri Mar 20, 2020 9:57 pm

Thank you so much for your help! So far, I have modes 1 - 3 working as expected. I am however having trouble with mode 4.

What I'm trying to accomplish is to have the dotstars light up in sections as the audio file plays. I know somethings not right but I'm stuck again.

when it switches to mode 4 I get this from the REPL screen:

Traceback (most recent call last):
File "code.py", line 93, in <module>
File "adafruit_dotstar.py", line 193, in __setitem__
ValueError: Slice and input sequence size do not match.
Attachments
window lighting code.txt
new code as written
(3.64 KiB) Downloaded 4 times

dman80601
 
Posts: 3
Joined: Mon Mar 16, 2020 8:48 pm

Re: Feather M4 Express with propmaker wing

by dastels on Sat Mar 21, 2020 11:23 am

That error is because you are trying to set a group of pixels to a single value. You need to provide a value for each pixel in the group:

Code: Select all | TOGGLE FULL SIZE
dot[1: 15] = [(255, 255, 255)] * 14


Note that indexes start at 0, not 1. I.e. the first pixel is at index 0, so dots[0:15] will give you the first 15 pixels at indexes 0 to 14. For the next 15 you'll want to use dots[15:30] and so on.

E.g.
Code: Select all | TOGGLE FULL SIZE
dot[0: 15] = [(255, 255, 255)] * 15


Dave

dastels
 
Posts: 3102
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.