Skip to content

Commit

Permalink
Added Windows app, Arduino code
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicklee committed Sep 29, 2016
1 parent 66f817b commit f52dafa
Show file tree
Hide file tree
Showing 40 changed files with 2,854 additions and 0 deletions.
90 changes: 90 additions & 0 deletions Flight_Sim_Basic/Flight_Sim_Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//Flight Simulator Code for 'Joystick to Arduino'
//By Dominick Lee

int incomingByte = 0; // for incoming serial data

int roll = 9; //Digital Pin for Roll
int pitch = 10; //Digital Pin for Pitch

int volts (float voltage) //this function converts voltage to analog 0-255 values
{
float analogval;
analogval = ((255 * voltage)/5); //equation

return analogval;
}


float getFloatFromSerialMonitor(){
char inData[20];
float f=0;
int x=0;
while (x<1){
String str;
if (Serial.available()) {
delay(5); //lower the better
int i=0;
while (Serial.available() > 0) {
char inByte = Serial.read();
str=str+inByte;
inData[i]=inByte;
i+=1;
x=2;
}
f = atof(inData);
memset(inData, 0, sizeof(inData));
}
}//END WHILE X<1
return f;
}


void setup() {
// initialize serial communication:
Serial.begin(57600);
pinMode(13, OUTPUT);

}


void loop() {
digitalWrite(13, HIGH); // set the LED on

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:

incomingByte = Serial.read();

if (incomingByte == 114) { //we got roll
Serial.println("roll");

float x = getFloatFromSerialMonitor();

Serial.print(x);
Serial.print("v");
Serial.print(" Analog ");
Serial.println(volts(x));

analogWrite(roll, volts(x));
}

if (incomingByte == 112) { //we got pitch
Serial.println("pitch");

float x = getFloatFromSerialMonitor();

Serial.print(x);
Serial.print("v");
Serial.print(" Analog ");
Serial.println(volts(x));

analogWrite(pitch, volts(x));
}



}

} //end loop

20 changes: 20 additions & 0 deletions Joystick/Joystick.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Basic Express 2008
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Joystick", "Joystick\Joystick.vbproj", "{E139A14C-D9A2-4CAE-89A2-B27BB99091B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E139A14C-D9A2-4CAE-89A2-B27BB99091B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E139A14C-D9A2-4CAE-89A2-B27BB99091B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E139A14C-D9A2-4CAE-89A2-B27BB99091B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E139A14C-D9A2-4CAE-89A2-B27BB99091B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added Joystick/Joystick.suo
Binary file not shown.
Loading

0 comments on commit f52dafa

Please sign in to comment.