-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66f817b
commit f52dafa
Showing
40 changed files
with
2,854 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Oops, something went wrong.