Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Will-Firgelli/d2cdf69edc829974885984b3fb8e4856 to your computer and use it in GitHub Desktop.
Save Will-Firgelli/d2cdf69edc829974885984b3fb8e4856 to your computer and use it in GitHub Desktop.
/* Firgelli Automations
* Limited or no support: we do not have the resources for Arduino code support
*
* This progam controls the speed of a linear actuator via a potentiometer input
*/
int RPWM = 10; //connect Arduino pin 10 to IBT-2 pin RPWM
int LPWM = 11; //connect Arduino pin 11 to IBT-2 pin LPWM
int potPin = A0; //analog pin that connects to centre potentiometer pin
int Speed, sensorVal;
void setup() {
pinMode(RPWM, OUTPUT);
pinMode(LPWM, OUTPUT);
pinMode(potPin, INPUT);
}
void loop() {
sensorVal = analogRead(potPin); //read user input from the potentiometer
if(sensorVal >= 512){ //extension
Speed = map(sensorVal, 512, 1023, 0, 255);
analogWrite(RPWM, 0);
analogWrite(LPWM, Speed);
}
else{ //retraction
Speed = map(sensorVal, 0, 511, 255, 0);
analogWrite(RPWM, Speed);
analogWrite(LPWM, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment