I’m trying to make a variable so that I don’t have to write Controller1.Axis3 way too many times.
For some reason it doesn’t like doubles but I really don’t want to risk using auto. Any help would be appreciated, I’m probably just being dumb. Thanks!
Controller1.Axis3 is an instance of a controller::axis class (actually a reference to one), you could do this
(use another reference to it)
const vex::controller::axis &a3 = Controller.Axis3;
while(1) {
Brain.Screen.printAt( 100, 220, "Axis3 : %4d", a3.position() );
this_thread::sleep_for(10);
}
or this
const auto &a3 = Controller.Axis3;
while(1) {
Brain.Screen.printAt( 100, 220, "Axis3 : %4d", a3.position() );
this_thread::sleep_for(10);
}
or if all you really need is to use the value of the axis several times, perhaps this.
while(1) {
// p will hold last position of axis3, it need updating each time through the loop
int p = Controller.Axis3.position();
Brain.Screen.printAt( 100, 220, "Axis3 : %4d", p );
this_thread::sleep_for(10);
}
3 Likes
Thank you very much!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.