I am teaching myself how to write code, and i am just wondering if this will work. I need it to change the throttle value and store the new value as throtte_val. It compiles but have had the chance to test it. throttle is on a pwm and throttle change is in increments of 10.
if (results.value==throttle_up){
throttle_val = throttle_val + throttle_change;
analogWrite(throttle,(throttle_val));
}
if (results.value==throttle_dn){
throttle_val = throttle_val - throttle_change;
analogWrite(throttle,(throttle_val));
There is no reason to have parentheses around throttle_val in these lines:
analogWrite(throttle,(throttle_val));
This code
throttle_val = throttle_val + throttle_change;
can be shortened to
throttle_val += throttle_change;
I'd prefer to see some white space in this, along with the { on the next line.
if (results.value==throttle_up){
More like this:
if (results.value == throttle_up)
{
The 2nd block of code should be preceded by else. The value.results variable can not take on a new value in the 1st block, so, it value.results was throttle_up, it can't also (or now) be throttle_dn.
Other than that, though, the code should work.
PS. Make your coding easier to understand by lining up open and close braces, and indenting code uniformly.