Using One Potentiometer to Change what another does...

Hi there;

Trying to make a basic dmx lighting controller via arduino. Currently have it successfully outputting DMX via the tinkerkit shield and am able to adjust 2 channels from 2 potentiometers i have connected.

What I would like to do is to have it so that one potentiometer defines the channel I want to adjust (0-512) and the second then adjusts the value on the channel I have chosen. (0-255).

Is there a method of doing this... I am suspecting that a lookup table might be a way of doing it but have very little idea on this regard.



You might be better off using a rotary encoder, trying to get 512 reliable positions from a potentiometer is not going to work, even 255 reliable positions.

Potentially; however for testing purposes i have a few potentiometers lying around so would like to use those to begin with.

Then instead of trying to fit all 512 channels in, maybe split it into 10 or something like that for testing.

Something like:

int potVal= analogRead(0);
int channel = map(potVal, 0, 1023, 0, 10);

See the reference on the map function

Not worth your time.

Seriously! :astonished:

Go get the rotary encoders and a LCD display and learn to program them.

Note a trick with the rotary encoders - you only use one! They have a push switch included so you switch directly from one function to the other. You do not even have to take your hand off the knob!

(This is pretty standard on medical equipment now.)

As has been explained, getting more than one or - at the most - two dozen positions from a potentiometer is quite ridiculous, You need the LCD display in any case (and they are dirt cheap).

This what i currently have -

#include <DmxSimple.h>

const int analogInPin1 = A5;  //Potentiometer Input 1 Pin
const int analogInPin2 = A4;  //Potentiometer Input 2 Pin

int sensorValue1 = 0;       //Potentiometer Input 1 (0-1023)
int sensorValue2 = 0;       //Potentiometer Input 2 (0-1023)
int outputValue1 = 0;       //ReMapped Output from Input 1 (0-255)
int outputValue2 = 0;       //ReMapped Output from Input 1 (0-255)

/*DMX Output Variables*/ 
int DMX1 = 0;
int DMX2 = 0;
int DMX3 = 0;
int DMX4 = 0;
int DMX5 = 0;
int DMX6 = 0;
int DMX7 = 0;
int DMX8 = 0;

void setup() {

pinMode(A5, INPUT);         //Potentionmeter Input 1 Pin
pinMode(A4, INPUT);         //Potentionmeter Input 1 Pin
DmxSimple.usePin(3);        //3 Is Required as that is the pin used by the DMX Shield
DmxSimple.maxChannel(512);  //The Number of Channels you would like to use in your Universe (Max 512)
void loop() {

DMX1 = outputValue2;
DMX3 = outputValue1;
DMX12 = 250;
DMX6 = 255;

/* The next lines in the format of DmxSimple.write(X, Y);  DmxSimple.write is a command added by the DMXSimple.h Libary
X is the Channel Number within the Universe (1-512) & Y is the Value of that specific channel (0-255) */
DmxSimple.write(1, DMX1);
DmxSimple.write(2, DMX2);
DmxSimple.write(3, DMX3);
DmxSimple.write(4, DMX4);
DmxSimple.write(5, DMX5);
DmxSimple.write(6, DMX6);
DmxSimple.write(7, DMX7);
DmxSimple.write(8, DMX8);
  // read the analog in value:
  sensorValue1 = analogRead(analogInPin1);
  sensorValue2 = analogRead(analogInPin2);
  // map it to the range of the analog out:
  outputValue1 = map(sensorValue1, 0, 1023, 0, 8);
  outputValue2 = map(sensorValue2, 0, 1023, 0, 255);


Thanks for your time on this by the way…

Paul__B, absolutely right on using one encoder with the built in button.

But you know how it is when you have a project you want to work on and waiting for a part to come is frustrating. This way he can get a start..

AndrewSeeds, I don't think you're going to get 255 points of data from a potentiometer.

No need to use map.

Use shift right.

Yeah I now understand that is the case - I will get a few on order and when they arrive will change the input that defines the variable.

The bit that's really stumping me is how to code the fact that the value of one variable changes which variable that the other rotary input's value is written to...

The bit that’s really stumping me is how to code the fact that the value of one variable changes which variable that the other rotary input’s value is written to…

Think about the problem in different way.

Imagine you have a value in a variable channelVal that define which channel you want to work with.
Imagine you have another variable brightnessVal with the brightness (or whatever) value.

One potentiometer (or, better, the rotary encoder) changes the channel value. The other potentiometer changes the brightness value.

Assuming (for demonstration) that the channelVal is the pin number of an LED (pretend the LEDs are channels) your code could be something like this

void updateChannel() {
  analogWrite(channelVal, brightnessVal);


That is really helpful; was thinking along completely different lines.

I shall go and play now...