Yeah, I'm a bit too excited...
So the parts have come in today. I love it when I see that big McMaster tube. Tis rather funny seeing it outside a workshop sort of environment though.
I worked out some code too. The code isn't all that complicated. Like I said earlier, the button is going to determine if the motor will turn on, and the pot will determine the speed the motor goes. If you're curious see the code below.
Construction is going to be starting shortly....
So the parts have come in today. I love it when I see that big McMaster tube. Tis rather funny seeing it outside a workshop sort of environment though.
I worked out some code too. The code isn't all that complicated. Like I said earlier, the button is going to determine if the motor will turn on, and the pot will determine the speed the motor goes. If you're curious see the code below.
Construction is going to be starting shortly....
// Kick Assist Code
// "Status" Kuo
#include <Servo.h>
/*
Talon Speed controllers work work the same way servos do for position I guess.
Analog write doesn't properly do the magnitudes properly as I've learned before.
*/
Servo talon; //creates a talon object
const int buttonPin = 2; // the number of the pushbutton pin
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
talon.attach(9); // attaches the talon on pin 9 to the servo object
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop()
{
// read the state of the pushbutton value:
int buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is...
if (buttonState == HIGH) {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 90, 179); // scale it to use it with the talon (servo object value between 0 and 180) but really 90 and 180 because we don't want the motor going backwards
talon.write(val); // sets the talon speed according to the scaled value
//delay(15); // waits for the servo to get there (I don't think this is nessessary for a speed controller)
}
//if the button isn't pressed, the motor won't turn on
else {
val = 90;
talon.write(val); // sets the servo position according to the scaled value
}
}
Comments
Post a Comment