Potentiometer Implementation

Maybe I misunderstood " the sound wouldn’t match up," and now that I actually take a second to think, I guess I don’t see how the sound wouldn’t match since ProffieOS would time the animation regardless of length, right?

Maybe it’s the control aspect that’s misleading. We’re talking about having the pot dial set the blade length, no?

Maybe this is what I read.
So not WavLen then, but something like Scale that would allow the pot to set the low and high speed range of the In/Out.

Would this be close?

InOutHelperL<Scale<AnalogReadPin<data4Pin>,Int<100>,Int<2000>>>

You would need an InOutHelperFuncX somewhere to make this work I think.

The way I had it set up, the pot wasn’t controlling the extend time, it was directly controlling the extension. If you moved the pot half way, the blade would extend half way.

ohhhh I see.
Direct, real time control. So in other words just a real time blade length adjustment, and just doing it quickly-ish from/to zero would look like extension or retraction.
Maybe crossing the zero barrier could trigger On(), and some detection of fast LED count decrease could trigger Off()

If that’s the use case, wouldn’t a slider on the same axis as the blade make more sense?
ooo a slider with a push-to-click feature could be cool. Then you’d have a button too.

That would be fairly easy to put into a prop, and it would work.
However, something that modulates and adjusts the sound on the fly would be even cooler. :slight_smile:

As I keep working on my lightsaber which I hope it’ll finally be ready soon, I like where all this is going…

I need to ask this just to be sure.

I only have one pad left that has analog functionality, and that’s TX.

RX is connected to the RFID board.

Is that ok?
Can I configure only RX for the RFID board and the TX pad as analog input without any conflicts?

It’s definitely possible, but I’m not sure if it will work right out of the box or not.
What will happen is that the serial port will configure the pin for serial, and the pot code will configure the pin for analog input. Whichever code runs last wins. Unfortunately, I kind of think the serial port initializer might run last, although I’m not sure.

If it doesn’t work, you should be able to fix it by adding this line:

  pinMode(txPin, ANALOG_INPUT);

here:

Hopefully setting the pin back to analog mode is enough to make it work.

Thank you!

I’ll try that!

Another option would be to define one of the neopixel data pads into a different one.

The thing is I need 3 data outputs for blade and accents and one “data2” is being used for the color LCD, so, I’ll need all four of them.

For the screen I’m using the pins you mentioned in the color LCD thread, for the RFID, I’m using the RX pad.

Buttons 1 and 2.

That only leaves TX as the only analog input available.

But if data4 could be reconfigured to, let’s say, Button3 pad, then I could use the “old” data4 pad to be the analog input.

Whatever works.

Any GPIO-capable pad can be used for neopixel data.

I tried this today and got the following error:

In file included from C:\Users\vicms\Desktop\ProffieOS-v7.8\ProffieOS\ProffieOS.ino:1385:
C:\Users\vicms\Desktop\ProffieOS-v7.8\ProffieOS\common\serial.h: In member function ‘virtual void RFIDParser::Setup()’:
C:\Users\vicms\Desktop\ProffieOS-v7.8\ProffieOS\common\serial.h:49:17: error: ‘ANALOG_INPUT’ was not declared in this scope; did you mean ‘NUM_ANALOG_INPUTS’?
49 | pinMode(txPin, ANALOG_INPUT);
| ^~~~~~~~~~~~
| NUM_ANALOG_INPUTS
exit status 1
Error compiling for board Proffieboard V3.

Do I have to include a file?

Also, do I have do define anything in the config file to enable analog reading?

And once enabled do the read value show in the serial console?

Oh, I guess it’s just INPUT, not ANALOG_INPUT.

This one didn’t give me any errors.

Thanks!

Is there a way to see the analog reads in the serial monitor?

Do I have to define anything in the config file or create a pot class or something?

It doesn’t seem like there is, you would need to add some print statements to the code.

That would also work.

This has been a long thread, what does your config file look like right now?

Here is the config file I’m currently using, very basic as I just finished putting the saber together.

The RFID is not currently working the RFID board is probably dead), that will require a rewire and I’m no doing that for now.

So the functionality I want to implement for now is the Potentiometer which is connected to the TX pad, the color LCD screen which is connected using the pads you indicated in the color LCD thread and while the RFID is not working, I want to use blade detect for the crystal, I connected blade (crystal) detect to button3 pad.

None of that is yet implemented in my config except for the RFID.

I don’t know how to set up the potentiometer or the blade detect.

For the potentiometer there are a few things I want to do which I hope it wont be too hard to code, but to start with I’d like to either change the color of the blade or make the blade go from stable to unstable.

For the crystal detect, I just want to implement a failing to ignite font when there’s no crystal and the rest of the fonts would play if there’s a crystal present.

EDIT: I’ve implemented crystal detect, so only the potentiometer and color LCD are left to do.
I’m getting errors in the config file when trying to set the color LCD, but I’ll leave that for the color LCD thread.

my_saber_config8.h (10.0 KB)

You need something like this in the CONFIG_BUTTONS sections

ChangeVariationAnalogReceiver color_changer;
PotClass pot(txPin, &color_changer);

Do I need to define anything in the CONFIG_TOP section?
It compiles but it’s not doing anything.
Right now it says #define NUM_BUTTONS 2, if this is considered a “button” shouldn’t it be set to 3?

No.

No, it’s not really a button.
Besides, NUM_BUTTONS is just a hint for the prop, buttons will send events either way, those events might just not do anything.

You can use monitor variance in the serial monitor to see if it’s doing anything or not.
Normally variance will change the color, but it depends on the style and the prop what actually happens.

Maybe it already is, and if it isn’t I don’t know where it would go best, but I feel like that might not be a bad idea to document… that the NUM_BUTTONS doesn’t change how ProffieOS itself handles the objects (or doesn’t)

Go here, click the edit button and make a suggestion:

It’s working now, the ground cable connected to the potentiometer somehow broke during the wiring process.

Now, I have a few questions:

  1. Is it possible to set the colors I want to cycle through?
    Like starting blue then as I turn the pot going to light blue then dark orange and then to red and avoid the other colors?

  2. Or if not possible to avoid colors is it possible to set the order?
    My pot goes from around 150 Ohms to 10,054 Ohms and at the highest value it actually repeats the first color set the lowest value.

  3. I noticed all neopixels change colors, even when they are assigned to different data pins, is it possible to program the board so it just changes specific sub blades?
    That way I could have it to only change the color of the crystal chamber, emitter and blade.

  4. The pot is part of hilt and when I detach the chassis from the hilt the resistance value goes to “infinity” (open circuit/zero volts), is it possible to make it ignore this value or values over 10K ohms in a way that if the value goes from whatever position withing the acceptable range to over 10K (or lower possible voltage achievable with this pot at 10K Ohms), it just stays in that last value read until it reads a new acceptable value? That way I can detach the chassis and it would retain those settings when I ignite it outside the hilt/not connected to the pot.

  5. What are the limits to using a pot?
    I’ll go more straight to the point with what I would like to do with it, maybe I’m being too ambitious but hopefully it can be done:

I want the saber to start blue at the highest value, and as I turn the knob down I want the blue to go to light blue, then as I keep going make the light blue start to slightly pulsate, and from there as I keep turning the value down I want it to go from pulsating light blue to dark orange, then to red and finally unstable red at the lowest value. I also want to make a font folder made out of four different fonts of my choosing and play a specific group of sounds based on the value of the pot/blade color settings.

It’s a lot, I know, but hopefully possible… :sweat_smile: