I need to output 0-5Vdc from my UNO, BUT.. I need it to go from 0 to 5V slowly raising only when I turn on an input and stop at it current state when I remove the input.
Then it needs to drive down to 0V when another input is pressed.
so just to clarify..
button1 Pressed = drive PWM output from 0..1..2..3..4..5V but if the button is released at 3 it will stop there until button2 is pressed and then 3..2..1..0V
any ideas?
i'm basically trying to simulate a scale being filled using 0-5V instead of a load cell.
so i open up product door and it fills to when i close the door.
I then discharge from my scale and it removes the 5V to simulate empting the scale.
note. I have a low pass filter setup to give me DC out
To what? The Arduino can actually only output 0 or 5V. It switches PWM pins on and off very quickly, so some devices think that they are getting values between 0 and 5V. If you really need 0 to 5V, you need a filter after the PWM pin.
I need it to go from 0 to 5V slowly
Slowly is not a defined term. "Incrementing by 1 every 3 seconds" is an implementable requirement. "Slowly" is not.
raising only when I turn on an input
Raising only while the pin is HIGH, or starting to raise only when the pin goes HIGH? Details matter.
and stop at it current state when I remove the input.
Stop the PWM or stop the incrementing?
so just to clarify..
button1 Pressed = drive PWM output from 0..1..2..3..4..5V but if the button is released at 3 it will stop there until button2 is pressed and then 3..2..1..0V
Different requirements are not clarification.
What parts of this are you having problems with (aside from defining the requirements)?
You need an interrupt-driven pwm generator - one that you can simply set the duty cycle and it will operate on its own, without your further intervention, to generate the desired duty cycle.
You will then poll the switch periodically (via a timer or a cycle counter for example). If the switch is on, you increment the duty cycle (until its upper limit). If the switch is off, you do nothing.
Similar process for the other switch but decrementing the dc instead.
dhenry:
You need an interrupt-driven pwm generator - one that you can simply set the duty cycle and it will operate on its own, without your further intervention, to generate the desired duty cycle.
That's exactly what analogWrite() does. No need for anything else.
UKPROGMR:
I need to output 0-5Vdc from my UNO, BUT.. I need it to go from 0 to 5V slowly raising only when I turn on an input and stop at it current state when I remove the input.
Then it needs to drive down to 0V when another input is pressed.
Since you have the PWM output already LP filtered and are presumably happy with it, and assuming you have two buttons connected which pull an input low, try something like this:
#define buttonDown X // whatever pin you use
#define buttonUp Y // whatever pin you use
#define output Z // must be a PWM pin
void setup (void) {
pinMode(buttonDown, INPUT_PULLUP);
pinMode(buttonUp, INPUT_PULLUP);
pinMode(output, OUTPUT);
}
long value = 0; // var to hold "load cell" simulated value
void loop(void) {
if(digitalRead(buttonDown) == LOW) {
if (value++ > 1023) { value = 1023; } // constrain high value
}
if(digitalRead(buttonUP) == LOW) {
if (value-- < 0) { value = 0; } // constrain low value
}
analogWrite(output, value);
delay(100); // adjust to your liking (speed of change)
}