FSX and RPM indicator (with servo SG90)

Hi everyone :slight_smile:
I’m looking to try making a tachometer, with the help of Link2fs (Thanks Jim), in the extractions page nº1, I select the <T, to rpm eng 1… but my problem is the code to make the servo moving with the inputs received from the fsx :

This is my code:

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 int CodeIn;// used on all serial reads
 
 int val;
 long int rpm;
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  
  Serial.begin(115200); 
 
} 
 
 
void loop() 
{
 
 {OTHER();}// Check for "Other" things to do. (Non extraction stuff)
  if (Serial.available()) {  //Check if anything there
    CodeIn = getChar();      //Get a serial read if there is.
    if (CodeIn == '=') {EQUALS();} // The first identifier is "=" ,, goto void EQUALS
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<" ,, goto void LESSTHAN
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?" ,, goto void QUESTION
    if (CodeIn == '/') {SLASH();}// The first identifier is "/"  ,, goto void SLASH (Annunciators)
  }
}

char getChar()// Get a character from the serial buffer(Dont touch)
{
  while(Serial.available() == 0);// wait for data (Dont touch)
  return((char)Serial.read());// (Dont touch) Thanks Doug
}

void OTHER(){
}

void EQUALS(){      
}

void LESSTHAN(){    // The first identifier was "<"
    delay (11);
    switch(CodeIn) {// 
    case 'T'://Found the second identifier "Engine 1 RPM"
    rpm = map(rpm, 0, 2500, 0, 179); 
    myservo.write('rpm');              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
       
}
}


void QUESTION(){    
}

void SLASH(){    
}

I’m new on this “world of arduino”, so I don´t know where is my error, …the arduino program don’t tell me that there is an error, bur the servo don’t have motion when I connect it to link2fs via COMM port.

Thanks in advance, I’m still waiting for suggestions from the experts :stuck_out_tongue:

 {OTHER();}// Check for "Other" things to do. (Non extraction stuff)

Several problems, here.

First, the curly braces are useless. Second, nothing goes on the same line after the {. Third, nothing goes on the same line as the }. Fourth, all capital letter names are, by convention, reserved for constants. OTHER is not a constant. It is a function.

    myservo.write('rpm');              // tell servo to go to position in variable 'pos'

That isn't what that code does. Single quotes are for single characters. Which ONE key did you press to get the one character in the single quotes? Why are you sending a letter (incorrectly) to the servo? Do you really expect it to move to position 'a', 'b', etc?

PaulS: First, the curly braces are useless.

True, but it's not a problem. And let me say most of such code comes from sample INO code included with LINK2FS, so it's not ricmaufer's fault... :-)

Second, nothing goes on the same line after the {. Third, nothing goes on the same line as the }.

Who said that? It's not a language specification, and that source compiles without any problem and/or warning and/or errors.

Fourth, all capital letter names are, by convention, reserved for constants. OTHER is not a constant. It is a function.

True, and I completely agree with you (it was the same thing I thought the first time). But, as said before, this is only a sample code made by LINK2FS author (and his programming style is quite "rough" IMHO), and it's neither voiding the compilation nor the program functionality. I personally loaded the samples from LINK2SF and working with them without any problem, so those "out of standards" are not causing the problem ricmaufer is complaining and asking help about.

That isn't what that code does. Single quotes are for single characters. Which ONE key did you press to get the one character in the single quotes? Why are you sending a letter (incorrectly) to the servo? Do you really expect it to move to position 'a', 'b', etc?

That's probably the point. I hope our friend will tell us if he solved or not... :-D