I have one pot controling bulb brightness (Analog In, Out Serial) but I need another pot to control ramp up/down time between two pwm values. So when state of the POT 1 changes from 0 to 100%, pwm value ramps up to 100% in 10 seconds (when pot 2 is also at max value) and vice versa.
Thank you in advance!
masterblaster92:
I still have nothing so I will look on that part of forum for help.
But in your initial post, you said you have 1 pot controlling the brightness. Isn't that a sketch that you already have? Did you try to study it and figure out how to add a second pot?
blh64:
But in your initial post, you said you have 1 pot controlling the brightness. Isn't that a sketch that you already have? Did you try to study it and figure out how to add a second pot?
Yes I have first half done, I just used AnalogInOutSerial example and set correct pins:
const int analogInPin = A2;
const int analogOutPin = 6;
int sensorValue = 0;
int outputValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(analogOutPin, outputValue);
delay(2);
}
Now I need another pot (A3) to control ramp up/down of PWM Pin 6...
SO you do have a sketch - great! Please read the sticky post at the top of the forum about how to properly post your code using code tags. It helps people help you by allowing them to quickly copy the code. You can also go back and edit your post to add the code tags.
With that example, you now need a second pot. You have identified the pin (A3) so what have you tried? Surely, you can figure out how to define this second pin in your code and how to read the value, no?
The next step would then be to figure out the relationship you want between the two values. You stated that if pot1 changes, you want the transition from the old value to the new value to be faster/slower depending on the value of pot2. Seems like there might be a little math involved there. You might want to rethink that specification since if pot1 changes from 128 to 129 (1 tick) and pot2 is at maximum, it would take 10 seconds to increment from 128 to 129 even though there are not intermediate values available.
blh64:
SO you do have a sketch - great! Please read the sticky post at the top of the forum about how to properly post your code using code tags. It helps people help you by allowing them to quickly copy the code. You can also go back and edit your post to add the code tags.
I am sorry, my bad , edited!
blh64:
With that example, you now need a second pot. You have identified the pin (A3) so what have you tried? Surely, you can figure out how to define this second pin in your code and how to read the value, no?
Yes of course, that's no problem.
blh64:
The next step would then be to figure out the relationship you want between the two values. You stated that if pot1 changes, you want the transition from the old value to the new value to be faster/slower depending on the value of pot2. Seems like there might be a little math involved there. You might want to rethink that specification since if pot1 changes from 128 to 129 (1 tick) and pot2 is at maximum, it would take 10 seconds to increment from 128 to 129 even though there are not intermediate values available.
If POT2 (ramp pot) is at 100%, and POT1 changes from 0 to 50% it would take 5 sec to ramp to that value (not 10 sec) and so on...
As for your example, POT1 isn't going to change from 0 to 50% instantaneously. By the time you have turned it from 0 to 50%, your arduino will have read that value tens if not hundreds of times. The arduino will see the change as a large series of incrementing values. How should the program react to that?
masterblaster92:
Yeap, that's where my abilities stop unfortunately.
Your abilities to articulate what should happen? If you can't describe the intended behavior, how do you expect to program it?
Try this: your rate pot (POT2) will give you a value from 0-1023. Lets say that is the number of milliseconds to delay after changing the PWM value based on POT1. To do that, you will have to remember the previous value you read from POT1 and compare it to the current value. If it is less, you decrement the PWM value by 1 and delay the value of POT2. If it is more, you increment the PWM value by 1 and delay the value of POT2. If it is the same, you do nothing. You then update the previous value to match the current value and do it all over again.
That is a starting point. Get that working. If the delay is too fast/slow, then you can work on scaling your POT2 value up or down by some factor to achieve what you want.