A Virtual Joystick – How Can You Make That ? – tutorial

Hello everybody, this is a tutorial in which a virtual  Excel joystick controlled by mouse movements on a scatter chart has been demonstrated . While in operation, a macro updates the coordinates of the pointer in two spreadsheet cells. The two coordinates are then incorporated in formulas which limit the range of motion of the joystick. Just like a real device the stick head movement is confined within a square (with a side length of 200 pixels) and so is the numerical output (limited to [-100,100] on both X and Y). Immediate applications of this joystick are: a race car game (acceleration, brake and steering), a flight simulator (emulates an airplane cockpit yoke or control stick – Roll+Pitch), a shooting game (azimuth and altitude cannon control), or a combination of the above applications.  Good luck, George

Usage: If the macro is stopped, click the chart to start it. It is a good idea to position the pointer in the origin of the chart before clicking, this way the cursor will roughly be positioned on top of the joystick head on the chart. The joystick position is controlled by the mouse movement. To stop the macro click the chart again.


This article has 11 Comments

  1. I need a simple 3 DOF / 2D simulation for a project my company is working on. I suspected that Excel had the capability of doing real time graphics, but my mechanical skills far exceed my computer skills. The joystick and flight simulator on this site indicate that it can be done. We’re mostly interested in determining the stability of the system when controlled manually (joystick). Would anyone on this site be interested in working on this? Please contact bob@desertaerospace.com

  2. I will be interested how the speed benchmarking work out. Size is not a particular issue; I have used MMULT to transform coordinates from ship axes to the helicopter flight deck for a spectral analyis (6 dof, real and imaginary parts, 50 or more frequency steps) giving a 12×12 matrix multiplied into a 12×50 matrix and followed this by solving simultaneous linear equations using the MINVERSE worksheet function. I was not ‘up against the clock’ though.

  3. Peter, I will start with the second question first: click the chart again when you need to stop the macro. I designed it on purpose like this (using DoEvents and a Boolean “flip” variable) so that you can start and stop it at any time by clicking on the same object – the chart. Also when you start the macro click in the origin of the chart. This way the handle of the joystick will follow your cursor.
    You might look down at me but I am not sure where to find the documentation. I found the macro on the internet and simplified it a little. I will use it a lot and I don’t feel any curiosity to find out what was in the mind of the person who designed it. I am not a VBA guru and I am not planning to be one. From the arsenal I pick a knife, a revolver and a shotgun and train myself how to use them very well. I don’t care about a thousand more weapons that are there until I find one that I am convinced it would give me a clear advantage while hunting (such as your MMULT and perhaps TRANSPOSE – I tested those this morning and now I need to benchmark them for speed). Thanks for the useful suggestions!!! George

  4. George.

    This looks really useful. I have searched the VBA help pages and only found mouse movement events in the context of controls and, even at that, the functionality seemed to require the control was on a form rather than a sheet.

    Can you point me to some documentation that will help me understand the syntax of the function:

    Public Declare Function GetCursorPos Lib “user32” (Some_String As POINTAPI) As Long ?

    The sheet did not respond very well to the Escape key but I eventually managed to shake the mouse monitoring off.

    Regards, Peter

  5. Juan Francisco, my interest is to have a fast growing educational site. I need to strike a balance between novelty, quality and quantity. I cannot afford to go back and double the amount of explanations for each post in the past. That would not help because most of visitors would be below that level of understanding anyway. If you say, in this post I don’t understand this or that, I can go and fix that. Or if you suggest a topic I might be able to write a new post for you (like I just did few days ago for someone else). I get a fair number of downloads from people and they rarely spend any time to post a comment which would help my site. Let me know what you don’t understand and I can add to that post or write a new one.
    Industrial engineering is a new interdisciplinary field which did not exist when I was a student. I believe that due to the growing trend of outsourcing from the US they invented a type of engineering which can deal, from a high level, with integrating different types of classical forms of engineering (some performed outside the US). I seriously doubt you can find a site like mine but focused on IE or focused on any other form of engineering. Excel is used massively from chemical engineering to aircraft design, but people do their work and would not take those sheets and post them, let alone make tutorials. Moreover how many people would look for that anyway?
    If you really intend to learn you have to do mostly everything by yourself. You have to enjoy, be persistent, obsessed and passionate. You must treat it like a hobby you are addicted to. A good book, a job, a good team, a good teacher will just give you a shallow learning, the illusion of learning. After that shallow learning people get fet up of the technical side and are ready to promote to management. I did learn this pretty late myself. But if you really want to be an true engineer you need to enjoy technical work, be passionate about it, be inventive and creative, and treat it like a good game. Learn it by doing it not by reading about it. That’s why you should treat this site as a source of tricks and inspiration and try to create the models by yourself as much as possible. Make better things than you see here. If you spend the time you can do it.
    And by the way there are plenty of explanations in these tutorials, you just have to follow more than one tutorial and also to google little details I might have missed.
    If you post comments and bring other people on the site who comment too, I can make a couple of IE models for you. Just let me know what you need and I will try to learn it and create something. Right now however, I am very busy trying to take this site off the ground. Cheers, Jorge

  6. Hello i’m not speak english very so i’ll write this letter in spanish sorry .
    I found very interesting your site , but it will better if you show more explanation o any example , because many of us don’t know better excel , please.
    Hola me llamo juan francisco soy estudiante de ingenieria industrial , encuentro muy interante su pagina web , quisiera saber donde puedo encontrar aplicaciones en excel igual que aqui pero destinadas a la ingenieria industrial , si Ud. añadiera mas de ellas en esta pagina seria muy provechoso , se despiede , Juan Francisco

Leave a Reply

Your email address will not be published. Required fields are marked *