27 December 2012

"FSUINO" is born

Yesterday night, Glenn had written up a small LUA script just to test out its ability to send out one FSX toggle button command through FSUIPC and LUA script to a 'com port'. 

He pointed me to a You Tube video tutorial on how to write a Arduino Sketch to read "serial data" through serial (com) port.

Didn't realize that code writing could be so sensitive to correct syntax. There were compile errors in almost every line of code I wrote. 

Finished code is as follows:-

int ledPin = 13;

void setup()
{
   Serial.begin(9600);         //Create Serial Object

  pinMode(ledPin, OUTPUT);
}

void loop()
{
 //Have Arduino wait to receive input
  
  while (Serial.available() == 0);
     
  //Read the input
  
   int val = Serial.read() - '0';
  
  if (val == 1)
  {
    Serial.println("LED is On");
    digitalWrite(ledPin, HIGH);
  }
  else if (val == 0)
  {
    Serial.println("Led is Off");
    digitalWrite(ledPin, LOW);
  }
  else
  {
      Serial.println("Invalid!");
  }
}

Long story short,

The code worked 'beautifully'.

I was able to use a preset key within FSX to illuminate the output LED of my Arduino Leonardo. 

This opens up many many new possibilities. 

Glenn, has most appropriately named this new interface as FSUINO (FSUIPC + Arduino).

Bravo FSUINO.

PS: Many thanks to Jeremy Blum for his excellent video tutorials on how to work with Arduino boards. The above code is straight out of Jeremy's video at this link.

No comments:

Post a Comment