Greetings folks, this post will be about developing your own game with the help of a Gyroscope sensor and an Arduino Nano using Arduino IDE and Processing 3. For those who don’t have any idea about what processing is, do check out Daniel Shiffman’s YouTube channel “The Coding Train” as it has great tutorials based on Processing 3, Processing JS (which is very helpful in developing web applications and games), ML5.js (For integrating Machine Learning on the Web). His tutorials are very easy to understand, even if you’re a beginner in the big bad world of programming. For the starters, you can start learning Processing either from Daniel Shiffman’s Tutorials or by reading the documentation.
If you’re already familiar with Processing or you just wanna skip the Processing part and just wanna jump straight towards playing with the Processing and Arduino code, you can keep reading ahead. In this tutorial, I’ll be explaining to you my Gyroscope Game Project named “Gyro-Drive” and how to run it. To understand the code, you can go through the comments and feel free to play with it, but don’t get carried away!
Firstly, the ‘gyro_game’ folder contains 5 .pde files, which is nothing but the extension for Processing and a folder, which consists of a .ino file, which is the extension for Arduino. Here are the attributes of every file:
- Camera.pde file is just for moving the camera around with our car.
- Game_1.pde file contains the code for the Serial communication between Arduino and Processing. It is required for loading all the scenes and looping them throughout the program as required.
- Scene1.pde file contains the layout and design for the introductory scene or the first page of my game.
- Scene2.pde contains the code for main part of the game, where we have to get the car moving and it contains the code for all the obstacles, reducing the score whenever there’s an encounter with the obstacles or whenever the car gets into the sandy area.
- Scene3.pde contains the code for final conclusion of the calculated score.
- Rest of the files are just background or sprite images.
Secondly, in the case of Arduino, I’ve taken the Analog data from the X-axis of the GY-61 Gyroscope Sensor and with the help of Serial communication, Processing reads that data from that specific COM Port and with that particular data, I’ve mapped it with the suitable dimensions in the game using the
That’s it for today, folks and feel free to play with the code and use it for the society. I know that it’s just a game but Gyroscope sensors have a lot of applications, while some of them might be helpful towards humanity and why not turn out a profitable business out of it, if it can help the people of our society and might as well benefit you?
If you’ve read this far, I’d like to thank you for doing so, your support is what gets me to write for you guys, so keep sharing my articles as you know that knowledge multiplies by sharing.
Neel Adwani (or neeltron) is your friendly neighborhood techie, a coder, traveler, stargazer and as you all know, a blogger. He has an endless range of interests in a commendable number of fields. He is an introvert, so don’t mess with him. He’s open to suggestions and criticism, though.