by rntechnologies on Fri Oct 12, 2018 8:41 am
There are a couple of ways to achieve this result, however without seeing the rest of your code its difficult to definitively say what the correct way is for you.
The code that you have written is fundamentally correct, however there are a few things to be careful of:
1. If the code execution rate is set pretty quick, you could have a case where in the time that it takes you to flick the switch to the on position and let it go, the code may have executed a number of times. You should perform a check in your code to check the last state of the switch, and only increment the number on the change event of the switch.
2. Are you setting up the switch to ensure that it operates in the same manner as a driver rotary switch? Ultimately you need to ensure that your switch is behaving in the same way as the rotary switch within your code. Then in tune you need to map the position (voltage, or in your case, emulated voltage) to the differing switch positions?
Nb. you can shorten up your code on the count by using: 'val += 1' rather than 'val = val + 1' and the same for 'val -= 1'.
Cheers,
Ryan
Regards,
Ryan
Powertune Australia