I’m a little bit lazy and a little bit lost
I’m looking to run up a motor via an ESC and Maestro. Has anybody got any code-snippets for accumulating a count over time? I need my script to drive the motor based on a potentiometer position. If however a push-button on another input is pressed, the script will add an arbitrary value to the pot position and drive the ESC to this slightly higher position. The script then lets some time pass, before repeating as long as the switch stays pressed. This ramps up the motor over-and-above the pot setting as long as I keep the button pressed. The switch is actually a bite-switch and this is a pot plus for hands-free (the bite-switch) system.
Below is my very rudimentary start. Any snippets to help would be much appreciated. Many thanks, Brendan.
# SCRIPT TO CONTROL A MOTOR ESC # # Inputs: # a) Potentiometer on '0' # b) Push-button switch on '1' # Output: One only - ESC on '2' # # Functionality: # 1) Drive servo '2' to position relative to pot '0' # 2) If Push-button '1' pressed go to a rampup sub and... # A) Get position of pot # i) Add pot value to a a small number # ii) Drive servo to this number, remember number # iii) Wait for a small time # Va) Is push-button still pressed? Yes - back to i) to repeat # Vb) Is push-button still pressed? No - forget accumulated number and back to 1) begin swt_rampup # Goto subroutine swt_rampup 0 get_position # Get the position of the Potentiometer 2 servo # Send this value to the servo (ESC) repeat sub swt_rampup begin 1 get_position 500 less_than # Is the swt active ("less_than") if return # If swt inactive break out of sub else delay 1000 if return endif endif repeat