When using AccelStepper my TeensyLC will not communicate with x-plane 10. Remove it and it works perfect. In the Teensy com window inside x-plane it shows the Teensy being connected and disconnected ok. Just no other communication. If I flash it with any of the FlightSimControls examples it works fine. Below is the code I tried with AccelStepper,
Code:
#include <AccelStepper.h>
AccelStepper stepper1(1, 1, 0);
FlightSimFloat adiroll;
const int homeButton = 7;
const int ledPin = 13;
byte hBval;
float cur_pos;
void setup() {
Serial.begin(9600);
stepper1.setMaxSpeed(100); //nice and slow for testing
stepper1.moveTo(-300);
stepper1.setAcceleration(70);
pinMode(homeButton, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
stepperHome(); //runs routine to home motor
adiroll = XPlaneRef("sim/cockpit2/gauges/indicators/pitch_electric_deg_pilot");
}
void loop() {
FlightSim.update();
cur_pos = adiroll * 3.33;
stepper1.moveTo(cur_pos);
stepper1.runToPosition();
Serial.print("Test position");
Serial.println(cur_pos);
}
void stepperHome() { //this routine should run the motor
hBval = digitalRead(homeButton);
while (hBval == LOW)
{
//backwards slowly till it hits the switch and stops
stepper1.moveTo(-400);
stepper1.run();
digitalWrite(ledPin, LOW); //indicates it's doing something
hBval = digitalRead(homeButton);
}
digitalWrite(ledPin, HIGH); //indicates it's doing something
stepper1.setCurrentPosition(0); //should set motor position to zero and go back to main routine
}