Potentiometer dilemma

Hi folks,

I have a VERY successful Arduino programs that I have been using for years. The issues is that I have been using a Conceneptics board for controlling the programs parameters for controlling my APA102 led strips. What I now want to do is use potentiometers to chose the parameters. I have 16 basic routines (one pot) and 3 pots for Speed, Brightness and Directions. This is for a childrens Christmas parade happening in about 2 weeks. I am at the end of roughly 20 hours trying to get this to work. I've tried all kinds of mapping controls as in:

int selector = analogRead(A0);
CurPatt =map(selector,0,255,0,16);

All I am getting is rapid blinking or nothing at all. I am using 10K rotary pots, top tap to 5 volts, center tap to A0, and bottom tap to ground. I've got a feeling that I need some extra circuitry on the center tap but have tried pullup and pull down resistors but now I'm seriously frazzled. I'm using an Arduino Mega so worse come to worse I could use some sort of switch array and that would be too costly and take too much time. Any ideas? I'm really up against the wall here!

Thanks in advance for any help!!

Joe B

int selector = analogRead(A0);
CurPatt =map(selector,0,255,0,16);

The analogRead function returns 0 to 1023. Shouldn't that be:

CurrPatt = map(selector, 0, 1023, 0, 16);

I really don't see how we can be of more help you without seeing your code.
Please read the forum guidelines to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Also, please post a schematic. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

Photos can be of help as well.

What is the resistance of the potentiometers? You can't feed the A/D inputs from very high-impedance sources. 10K pots should be fine, but 100K might not work properly.

A 0.1uF ceramic capacitor from the potentiometer wiper to ground will often make the pot readings more stable. The cap will make a low pass filter that blocks noise from effecting the readings.

If you are using a higher resistance pot, ie greater than 10K, the cap will lower the effecive impedance.

I dislike the map() function because it obscures what is really happening.

Why not int CurrPatt = selector / 64;

Can you show a useful part of your code - eg read the pot and generate a useful number?

here is the actual relevant code.
void LoadPalette()
{

//CurPatt =7;

CurPatt = map(analogRead(A0),0,255,2,7);

currentBlending = LINEARBLEND;
RunManual();
static uint8_t startIndex = 0;
startIndex = startIndex + CurSpeed; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(20);

}

Everything else is irrelevant because it has to do with reading from a DMX card which I said works BEAUTIFULLY across several HUNDRED parameters I use 24 DMX channels and if I had the power in my vehicle I'd just use the whole computer setup unfortunately I'm limited to 150 watts which gives me about 300 leds to pay with at 5 volts. I though how hard could it be to put a simple pot attached to a Mega. There is a 5volt regulated supply that powers both the Mega and the LED strips. I connect one end of the 10K pot to 5Volts, the other end to Ground. The wiper goes to A0. Period! I built an enclosure with housing everything and the LED strips connect via mini PCB screw terminals. THAT'S IT!
I think the .1uF cap is something I have yet to try and I've noticed bringing down the map to 0,128,1,8 gets me closer to the patterns I want. Will be trying the selector/64 code after I'm done. Again thanks with all the help!!! I'm using at least 6 Arduinos thru my lighting systems so I DO APPRECIATE the help!!!

Best,

Joe B

All the code is relevant. Without it, we can not see the definitions of your variables, for example.

If you don't want to post everything, please post an MRE.
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966/1#minimal-reproducible-example

Also, since hardware issues were mentioned, please post a schematic.

John Errington and Ground Fungus,

You are geniuses! I combined adding the cap AND NOT using MAP and now I'm there! Do yoy guys get point for correct solutions, I HOPE!!
Of course now I have to goback thru a TON of codee and find all the MAPs and see if there's a better way!!!

THANKS GUYS!!

Joe B

For the same spacing of #16 I would use
CurrPatt = map(selector, 0, 1024, 0, 17); // 0-1023 = 0-16
Otherwise #16 is only one A/D value wide.
Leo..

Only if you click the solution box under the single reply that helped you crack the problem.

Appendix

For the mathematically inclined, here’s the whole function

long map(long x, long in_min, long in_max, long out_min, long out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}