/* 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