A LED visualization tool for the 42 School's Philosophers project that brings the dining philosophers problem to life through a NeoPixel LED strip.
doc_2024-11-29_18-48-31.mp4
NeoRing provides a visual representation of the dining philosophers problem by connecting to the Philosophers project output. Each philosopher is represented by an LED on the strip, with different colors indicating their current state.
Each LED represents a philosopher with the following color codes:
- 🟡 Yellow: Philosopher is eating
- 🔴 Red: Philosopher is thinking
- 🔵 Blue: Philosopher is sleeping
- 🟢 Green: Philosopher has finished all meals
- Raspberry Pi (or similar board with SPI support)
- NeoPixel LED strip
- Appropriate power supply for the LED strip
- Jumper wires for connections
- Python 3.x
- CircuitPython NeoPixel library
- Compiled Philosophers project from 42 (on Raspberry Pi)
- Clone this repository:
git clone https://github.com/julioformiga/philo_ring
- Install the required Python package:
pip3 install adafruit-circuitpython-neopixel
- Connect your NeoPixel LED strip to the Raspberry Pi:
- Connect the data input to the SPI MOSI pin
- Connect power and ground appropriately
You can adjust the following parameters in neoring.py
:
NUM_PIXELS = 35 # Number of philosophers/LEDs
PHILO_TIME = 500 # Time to run simulation
PHILO_EAT = 200 # Time to eat
PHILO_SLEEP = 200 # Time to sleep
PHILO_EAT_N = 3 # Number of times each philosopher must eat
DELAY = 1 # Delay between updates
- Make sure your Philosophers executable is in the same directory
- Run the visualization:
python3 neoring.py
The LED strip will start displaying the philosophers' states in real-time. Each LED represents one philosopher, and the colors will change according to their actions.
- Ensure the 'philo' executable has proper permissions:
chmod +x ./philo
- Check if your LED strip is properly connected to the SPI pins
- Verify that your power supply can handle the number of LEDs you're using
Feel free to open issues or submit pull requests if you have suggestions for improvements or find any bugs.