The central concept behind the RANPW project is to create a dynamic, Tamagotchi-inspired tool enriched with a selection of games (LCatch, Pong, and LockY) and productivity applications (Cronometer and Termometer).This versatile platform encourages high modularity, enabling individuals with basic C++ knowledge to seamlessly develop and incorporate their custom apps and games.RANPW is designed to operate on the mbed NXP LPC1768 microcontroller, coupled with the mbed application board.
For a visual demonstration of the RANPW project, you can watch my YouTube video here.
Used hardware and libraryLCD: C12832
The 32x128 pixel LCD display serves as the primary visual interface for all interactions within the application. To achieve seamless control over the display, I've customized the C12832.h library to ensure compatibility with the project's broader software ecosystem.
Joystick
The joystick plays a pivotal role in navigating through all application interfaces. Its management is facilitated through the APIs provided directly by "mbed.h, " which can be accessed here.
Potentiometer
Both potentiometers are integral to specific user interactions, with one notably enhancing gameplay in the LockY game. The control of these potentiometers is streamlined through the APIs provided by "mbed.h, " as detailed here.
Temperature sensor: LM75BD
The LM75BD temperature sensor is utilized in the "Termometer" application to capture environmental temperature data. The sensor is integrated into the project using the LM75B.h library, with minor modifications to ensure compatibility with the Embed OS CE platform.
Accelerometer: MMA7660
The MMA7660 accelerometer contributes significantly to user interactions, particularly in the Hell and Pong games. To collect data from this component, the MMA7660.h library has been employed with slight modifications to align it with the project's requirements.
Thread overviewAt startup, RANPW initializes three distinct threads to manage various aspects of its functionality:
Thread 1: User interface and interaction
This thread is responsible for overseeing the entire user interface and facilitating interaction with end-users. It dynamically creates and initializes instances of all apps and games while orchestrating their display on the LCD screen. Further insights into this thread's workings can be found in the Interaction.h and Interaction.cpp files.
Thread 2: Kraken's management
Thread 2 operates on a straightforward principle, employing basic rand() functions to introduce wait times of 1 to 5 minutes. During these intervals, it randomly decreases the pet's hunger by a value ranging from 1 to 5. Should the hunger level plummet to zero, the pet's life diminishes at varying rates—1, 2, or 3 points per minute. Conversely, if hunger surpasses 20, the pet gains 1 life point. Notably, both life and hunger levels have a cap of 25. Detailed insights into this thread's functionality are available in the live() function within Kraken.cpp.
Thread 3: Data saving management
Thread 3 operates with a clear focus on data integrity. It consistently monitors the data stored in the members of the ConcurrentData structure. This structure is vital for ensuring safe data access across multiple threads. When disparities between the stored data and in-memory data are detected, Thread 3 takes action, overwriting the data and saving the respective file in the device's internal memory.Detailed insights into this thread's functionality available in DataSaver.h and DataSaver.cpp
Implementation analysisIn the process of realizing the RANPW project, I've meticulously crafted different classes to lay the foundation for its functionality and modularity. Each of these components plays a specific role in the project's architecture:
ConcurrentData
This essential structure serves as the backbone for managing concurrent data access across multiple threads. It ensures data integrity and consistency, preventing conflicts and race conditions.
DataSaver
The DataSaver class is responsible for handling data saving and data loading operations, ensuring that changes to critical data are persistently stored in the device's internal memory.
Interaction
The Interaction class serves as the central hub for user interface management. It oversees the creation and initialization of app and game instances, orchestrates their display on the LCD screen, and manages user input via various hardware interfaces.
Kraken
The Kraken class embodies the behavior and lifecycle of the virtual pet, monitoring key metrics such as hunger and life. It simulates the pet's interactions with the user.
Bag
The Bag class manages the virtual inventory system, allowing users to collect and interact with food items within the application. It enhances gameplay and engagement.
Cronometer
The Cronometer is a specialized application designed to provide users with a versatile stopwatch.
LCatch
LCatch is one of the interactive games featured in RANPW. It provides an engaging experience where users can test their reflexes and coordination.
What sets LCatch apart is its incremental speed feature, where the game progressively increases in difficulty as players successfully capture objects.
LockY
LockY is another game that offers users a unique challenge. It leverages hardware components like potentiometers for gameplay.
Pong
In Pong, player use the accelerometer as a unique input method to control the paddle and engage in the timeless challenge of bouncing a ball.
Hell
Hell is a captivating minigame tucked within the RANPW project, offering a distinctive twist on the gaming experience. Unlike other games, Hell only surfaces when the Kraken's life reaches zero, triggering the Kraken's respawn process.
Distinguished by its lack of a tutorial, Hell immerses players in a realm where they need to discover how to play by hiself.
Termometer
This class allow users to monitor temperature levels in their environment. What sets this component apart is its ability to visualize temperature data through a graph.
How to installBinary
All that is necessary is to download the binary available here and then insert it into the internal storage of the mbed NXP LPC1768.
Compile yourself
To compile it yourself, I recommend following the official mbed OS CE wiki instead.
In particular I recommend, once the development environment has been configured, you can chose to compile it:
- On the command line
- Using the CLion IDE
- Using the VS Code IDE
Remember that if you add something new to the project you need also to add it to the CMakeList.txt file
Future improvementsSecure data storage
Enhance data security by implementing minor encryption measures for all saved data. This safeguard prevents unauthorized user modifications and ensures data integrity.
Code refactoring
Optimize and streamline the codebase with the following refactorings:
- Game as superclass
We are planning to redesigning all the game components to have a common superclass, promoting code reusability and consistency among different games.
- App as superclass
Similarly, create a superclass for apps within the project to standardize their structure and behavior, making it easier to add new apps.
- Doxygen documentation
Add more app
- Mouse
An app that give the ranpw the ability to simulate a mouse, users can interact with their computer systems by controlling the mouse cursor's movement and clicks directly from RANPW.
- Rduck
An app that, give the script thanks to a USB stick, it allows the device, to emulate the behavior of a "Rubber Ducky.
Music to evrything
Integrate music and sound effects into various aspects of the project to enhance the overall user experience and immersion.
- Setting for music
Implement user settings that allow users to control music and sound effects, granting them the option to enable or disable audio as per their preference.
Hardware
- 3D printable case
Design and create a 3D-printable case for the project.
- Custom PCB
Make a custom PCB to integrate all the need hardware in a more compact manner.
Comments