From 64580d8fa7e44ac95698b07bb52713f0461d607b Mon Sep 17 00:00:00 2001 From: plane000 Date: Tue, 15 May 2018 15:30:50 +0100 Subject: [PATCH] Added arduino joystick mouse --- .../Joystick Controler/Joystick Controler.sln | 25 +++++++ .../Joystick Controler/App.config | 6 ++ .../Joystick Controler.csproj | 54 +++++++++++++++ .../Joystick Controler/Program.cs | 68 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ C++/Arduino/Joystick_Mouse/Joystick_Mouse.ino | 20 ++++++ C++/Arduino/Joystick_servo/Joystick_servo.ino | 19 ++++++ C++/Arduino/Tempsensor/Tempsensor.ino | 2 +- 8 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler.sln create mode 100644 C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/App.config create mode 100644 C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Joystick Controler.csproj create mode 100644 C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Program.cs create mode 100644 C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Properties/AssemblyInfo.cs create mode 100644 C++/Arduino/Joystick_Mouse/Joystick_Mouse.ino create mode 100644 C++/Arduino/Joystick_servo/Joystick_servo.ino diff --git a/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler.sln b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler.sln new file mode 100644 index 0000000..c9d2e41 --- /dev/null +++ b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27428.2043 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Joystick Controler", "Joystick Controler\Joystick Controler.csproj", "{BFB50E90-747D-451A-BEDE-267D1A54EF0A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BFB50E90-747D-451A-BEDE-267D1A54EF0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BFB50E90-747D-451A-BEDE-267D1A54EF0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BFB50E90-747D-451A-BEDE-267D1A54EF0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BFB50E90-747D-451A-BEDE-267D1A54EF0A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DBCC330F-291C-4EA1-877A-8504287D68AF} + EndGlobalSection +EndGlobal diff --git a/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/App.config b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Joystick Controler.csproj b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Joystick Controler.csproj new file mode 100644 index 0000000..7888aab --- /dev/null +++ b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Joystick Controler.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {BFB50E90-747D-451A-BEDE-267D1A54EF0A} + Exe + Joystick_Controler + Joystick Controler + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Program.cs b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Program.cs new file mode 100644 index 0000000..af9704f --- /dev/null +++ b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Program.cs @@ -0,0 +1,68 @@ +using System; +using System.Text.RegularExpressions; +using System.Drawing; +using System.IO.Ports; +using System.Windows.Forms; + +namespace Joystick_Controler { + class Program { + static void Main(string[] args) { + Console.CursorVisible = false; + var reader = new ArduinoSerialReader("COM3"); + + Console.ReadKey(); + } + } + + class ArduinoSerialReader { + private SerialPort serialPort; + + public ArduinoSerialReader(string portName) { + try { + serialPort = new SerialPort(portName); + + serialPort.Open(); + serialPort.DataReceived += dataReceived; + } catch { } + } + + private void dataReceived(object s, SerialDataReceivedEventArgs e) { + string fromPort = serialPort.ReadLine(); + + Console.SetCursorPosition(0, 0); + Console.WriteLine(fromPort); + + int[] XY = parser(fromPort); + MouseTranslator translate = new MouseTranslator(XY[0], XY[1]); + } + + private int[] parser(string input) { + int[] output = new int[2]; + string pattern = @"X:(-?[0-9]+)Y:(-?[0-9]+)"; + input.Trim(); + + try { + Match match = Regex.Match(input, pattern); + output[0] = int.Parse(match.Groups[1].ToString()); + output[1] = int.Parse(match.Groups[2].ToString()); + } catch { } + + return output; + } + } + + class MouseTranslator { + private int joyX; + private int joyY; + + public MouseTranslator(int x, int y) { + joyX = x; + joyY = y; + moveMouse(); + } + + private void moveMouse() { + Cursor.Position = new Point(Cursor.Position.X - joyX, Cursor.Position.Y - joyY); + } + } +} diff --git a/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Properties/AssemblyInfo.cs b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2c42c25 --- /dev/null +++ b/C++/Arduino/Joystick_Mouse/Joystick Controler/Joystick Controler/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Joystick Controler")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Joystick Controler")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("bfb50e90-747d-451a-bede-267d1a54ef0a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/C++/Arduino/Joystick_Mouse/Joystick_Mouse.ino b/C++/Arduino/Joystick_Mouse/Joystick_Mouse.ino new file mode 100644 index 0000000..3cade21 --- /dev/null +++ b/C++/Arduino/Joystick_Mouse/Joystick_Mouse.ino @@ -0,0 +1,20 @@ +#define XJOY A1 +#define YJOY A0 + +void setup() { + Serial.begin(9600); +} + +void loop() { + int joystickX = analogRead(XJOY); + int joystickY = analogRead(YJOY); + + Serial.print("X:"); + Serial.print(((joystickX+520)/10)-103); + Serial.print("Y:"); + Serial.print(((joystickY+520)/10)-103); + Serial.print(" "); + Serial.println(); + + delay(50); +} diff --git a/C++/Arduino/Joystick_servo/Joystick_servo.ino b/C++/Arduino/Joystick_servo/Joystick_servo.ino new file mode 100644 index 0000000..344f5d0 --- /dev/null +++ b/C++/Arduino/Joystick_servo/Joystick_servo.ino @@ -0,0 +1,19 @@ +#define XJOY A1 +#define YJOY A0 + +void setup() { + Serial.begin(9600); +} + +void loop() { + //delay(500); + int joystickX = analogRead(XJOY); + int joystickY = analogRead(YJOY); + + Serial.print("X: "); + Serial.print(((joystickX+520)/10)-103); + Serial.println(); + Serial.print("Y: "); + Serial.print(((joystickY+520)/10)-103); + Serial.println(); +} diff --git a/C++/Arduino/Tempsensor/Tempsensor.ino b/C++/Arduino/Tempsensor/Tempsensor.ino index 937bd10..1ab2db2 100644 --- a/C++/Arduino/Tempsensor/Tempsensor.ino +++ b/C++/Arduino/Tempsensor/Tempsensor.ino @@ -1,4 +1,4 @@ -#include +lol#include #include #include