I am working on a project where I need to adjust a mapped value based on a switch position, but then I would like to ramp the the new analog data when I write it.
An example, lets say we want to make a button output different voltage (serial robot controller). From my knowledge it will look something like this:
if( adjenpos == 1) {
boostbtnout = map(boostbtnin, 0, 1023, 0, 51);
}
else if( adjenpos == 2) {
boostbtnout = map(boostbtnin, 0, 1023, 0, 102);
}
else if( adjenpos == 3) {
boostbtnout = map(boostbtnin, 0, 1023, 0, 153);
}
else if( adjenpos == 4) {
boostbtnout = map(boostbtnin, 0, 1023, 0, 204);
}
else if( adjenpos == 5) {
boostbtnout = map(boostbtnin, 0, 1023, 0, 255);
}
Now with option 3, taking a button which has an on/off value of 0 or 153, I want to ramp the value 0 to 153 over a prescribed rate, instead of just on or off.
My assumption is to do something similar to this inside the loop:
boostramp = 1
boostbtnvalue = analogRead(boostbtnout)
analogWrite(boostbtn, boostbtnvalue);
if ( boostpwr <= boostbtnout){
boostpwr = boostpwr + boostramp;
I know this is not correct, but how do I inject the new mapped values into a rampped type of function?
Thanks!