Added arduino joystick mouse

This commit is contained in:
plane000
2018-05-15 15:30:50 +01:00
parent 16ddbd0dbb
commit 64580d8fa7
8 changed files with 229 additions and 1 deletions

View File

@@ -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

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BFB50E90-747D-451A-BEDE-267D1A54EF0A}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Joystick_Controler</RootNamespace>
<AssemblyName>Joystick Controler</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -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);
}
}
}

View File

@@ -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")]

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -1,4 +1,4 @@
#include <DHT.h>
lol#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>