#EDIT: Controlling multiple LEDS with the propmaker and neokeys

1 messages · Page 1 of 1 (latest)

ancient heron
#

Hey, so I'm starting a thread for this as not to clog up the main chat. I'm currently trying to control multiple servos with a propmaker. I have built a keyboard using 8 neokeys that plays a fart SFX when you hit a key. I had the idea that as the key is pressed a servo makes a 3D printed figure bounce off a toilet when the key is pressed and fall back when released. 8 figures in total, one for each key. I have 8 servos and a servo controller attached above. I have yet to master servos so I do need help getting it all working. Firstly, looking at the pics above did I hook it up right? the one servo I have hooked up moved a bit, and the power light on the controller is lit up.

#

I only had a 12V supply for the controller and noticed a slight bit of head on the servo. It says 5V so should i get a 5V supply instead?

half cave
ancient heron
#

I ordered a 5V

half drum
#

You can attach it with stacking headers on top of the Prop-Maker, or you can use a https://www.adafruit.com/product/2890, which is out of stock on our site, unfortunately, but is in stock at Digi-Key. Also there are triplers, https://www.adafruit.com/product/3417, and quads

half drum
ancient heron
#

Yeah and I kinda need the wires so I can spread out the servos

#

Or rather fit it in the enclosure

#

My 5V supply is arriving today

#

So when it does I’m going to need help figuring out controlling it

ancient heron
#

ok my power supply arrived, so i can start trying to figure out the servos. here's the code that i'm currently using in circutpython

#

first thing i have to do is get the servo control working

#

then i can work on linking the 2

#

The idea was when you hold down the neokey, the noise plays until you let go then it stops. That is currently setup. (thanks to @half drum for helping me with that) The next step is to add a function that moves the servo when the key is held down then when the key is released the servo moves back to its original position

ancient heron
#

Here’s where the finished figures will go

#

Just to give you an idea

#

I’m still trying to figure out the servos

ancient heron
#

Ok so I have a much less impressive/simple idea. Instead of servos, LED bulbs that light up in the window like an old love tester

#

I found out the servo controller I got also works with LEDS

#

So I can still use that

ancient heron
#

EDIT: Controlling multiple LEDS with the propmaker and neokeys

#

Just edited the thread as not to start another one

#

https://www.adafruit.com/product/4980 I asked this in the projects forum but is there any way to solder/attach external wired LEDS to each key so they can illuminate outside of the board. The code for lights is already in the neo key circutpython code (currently tuened off) but its directly under each key

#

I have this which can also control LEDs but not sure how to code it so the prop maker recognizes it

#

I DO have a spare neokey

#

Which I could experiment with

#

But any advice/guidance would be a help

half drum
# ancient heron But any advice/guidance would be a help

if you unplug one of the switches you can see the NeoPixel underneath. Since the switch body is clear, a light source in the back somewhere will show through. If you want to use a NeoKey, then you don't need the servo board: just run a STEMMA cable to the NeoKey and see its guide for examples

#

If you want to use some other LED, you can just tape or glue it to the back of the switch. Mounting the switch is the hard part. Or you can snap it into a hole and solder to the terminals

#

we sell pushbuttons with LEDs inside but they are pretty big: 16mm minimum

ancient heron
half drum
#

no, but just hold a switch in front of an LED

#

have you tried using the neokey?

#

I mean just to try it out

ancient heron
#

One sec

half drum
#

same idea on a macropad, if you have one

ancient heron
#

When you say switch do you mean the neokey board or this:

#

I assume you mean the board itself

half drum
# ancient heron

the first - the bare switch. All I mean is the plastic is clear, which is how it lights up.

#

If your project could use two NeoKey's, that's a solution, but maybe they're too big

ancient heron
#

I was wondering initially if I could just wire LEDs on long wires to each key but looking at it it seems I don’t have room in there

#

I guess I have to do it in circuit python

#

Through the prop maker

#

Then use the other board to connect the LEDs

#
def get_pressed_button_number():
    # Get all the button states and concatenate into one list.
    button_states = neokey1.get_keys() + neokey2.get_keys()

    # If they are all False, return None
    if not any(button_states):
        return None

    # Get the first pressed button (the first True in the list)
    return button_states.index(True)

def set_button_color(button_number, color):
    # Choose which neokey to use based on the range: 0-3 or 4-7.
    if button_number <= 3:
        neokey1.pixels[button_number] = color
    else:
        neokey2.pixels[button_number - 4] = color

# Play the selected file.
def play_file(filename, current_button_number):
    print("Playing", filename)
    with open(f"/sounds/{filename}", "rb") as file:
        audio.play(audiocore.WaveFile(file))
        while audio.playing:
            # Did a different button get pressed?
            if get_pressed_button_number() != current_button_number:
                audio.stop()
                return``` in code, the only thing I have a hunch on is the LED code would go in the middle somewhere
#
    # Choose which neokey to use based on the range: 0-3 or 4-7.
    if button_number <= 3:
        neokey1.pixels[button_number] = color
    else:
        neokey2.pixels[button_number - 4] = color
#

I THINK I have to edit this part

half drum
#

so you want both the keys and the separate LED's to light up?

ancient heron
#

The keys don't light just the seperate LEDs

#

I.E. I want the keys to remain unlit

half drum
#

you're not actually using neokeys for this project, right?

ancient heron
#

Well each piano key is attached to one of the Neokeys

half drum
#

i see

ancient heron
#

these are attached to a propmaker board with a speaker

#

And the propmaker is attached to this controller which I read can control LEDs too

half drum
#

well, you could put a NeoPixel strip behind the holes in the printed menu board, or put individual LEDs there, or individual NeoPixel LEDs. You could use something like Lite-Brite Pins in the holes to let the light through. Or the NeoPixel "globe" LED's I linked to earlier. Or wire a resistor to each LED and connect them to the servo boards outputs

ancient heron
#

I think the servo board outputs would be best

#

To answer your question above

half drum
#

do you have some LED's already?

ancient heron
#

Yes

#

I have wires and resistors somewhere too

half drum
#

but you don't like how they look if you put them in the holes?

ancient heron
#

Oh that I fixed

#

I found these Xmas ornaments on sale

half drum
#

so you are just wondering about how to turn them on with the servo board?

ancient heron
#

So my plan is to feed the LEDs in the backs

#

Yes

half drum
#

which board is this again?

ancient heron
#

the servo controller?

half drum
#

yes

ancient heron
#

this one

#

basically

#

i had it in my bin of parts

half drum
#

I'd increase the .frequency to something higher like 1000 so you wont see flicker.

#

to turn an LED, set the duty_cycle to something non-zero. to turn it off, set the duty_cycle to zero

ancient heron
#

I'll futz around with this to see if I can figure it out

half drum
#

i am going shopping

ancient heron
#

ok, wish me luck and thanks for your help

#

i really appreciate it

ancient heron
#

ok, getting somewhere i think. the controller is connected to the propmaker sucessfully (I was getting an error but managed to figure out I had the wires wrong so i fixed it)

#

its a matter of editing the currenct code. i have 1 led wired as a test

ancient heron
#

I ALMOST GOT IT

#

I got it so when I press a key the led lights up then when i release the led shuts off. I now need to figure out how to to get each key to light a seperate led on a different channel on the servo controller

#
    0x000000,
    0x000000,
    0x000000,
    0x000000,
    0x000000,
    0x000000,
    0x000000,
    0x000000,
    ]
``` I think I have to edit these values but I'm not sure
half drum
#
while True:
    # May be None, if no button pressed
    button_number = get_pressed_button_number()
    pca.channels[button_number].duty_cycle = 0
    if button_number is not None:
        # Light up the chosen button.
        set_button_color(button_number, BUTTON_COLORS[button_number])
        pca.channels[button_number].duty_cycle = 0x7FFF   # change value to change brightness
        # Play the chosen sound. If another button is pressed, stop early.
        play_file(FILES[button_number], button_number)
        set_button_color(button_number, 0)
#

You can take away all the set_button_color() if you don't want the NeoKeys to light up.

ancient heron
#

It gave me an error saying “list indices must be integers not Nonetype” on the line “pca.channels[button_number]

half drum
ancient heron
#

I’ll check this code out in a sec

#

Thank you again

ancient heron
#

And it works!!!

#

Thank you so much man!

ancient heron
#

You have no idea I’ve been working on this thing for over a year

#

I’ll finally be able to finish it