RAMP
RAMP copied to clipboard
Beginner Question
Hi Sorry to bother you with this but I have a general question. Both the examples show the interpolation running in the setup function. When I move it to the loop function it doesn't work for me. Can you tell me what I'm doing wrong?
`#include <Ramp.h> // include library
ramp myRamp; // new ramp object (ramp
void setup() { Serial.begin(9600); // begin Serial communication myRamp.go(0); }
void loop() {
myRamp.go(255, 1000);
Serial.println(myRamp.update()); // update() return the actual interpolation value delay(100); // }`
The serial monitor just returns the value I set in setup.
The problem here is that you call myRamp.go(255,1000) at the start of each loop, then immediatly myRamp.update().
So basically this is what you're doing :
in the setup: set the ramp object to 0
first loop: set the ramp desitnation to 255 in 1000 ms update the ramp while printing wich will result in 0 because it occurs just a few ns later the go call wait for 100 ms
second loop and following: set the ramp destination to 255 in 1000 ms // as it has not been updated since the last loop it will still start from 0 update this new ramp while printing wich will still result in 0 for the same reason and so on...
If you move myRamp.go(255,1000); after the myRamp.go(0); line in your setup the program will interpolate correctly for 1 second. You have to take care that the go method is mean to be driven by trigger event and to be called constantly ;-)
Thanks for the reply! I will give that a try.