This project is an implementation of the popular game Simon, for the RaspberryPi using a breadboard, some LEDs buttons.
To implement the game, I decided to implement a custom Linux driver to control the LEDs and button using the built-in GPIO pins. The driver code is, as expected, in the driver directory.
In order to build the driver you to install your kernel header files. Do so with the following command -
sudo apt install -y kernel-headers-$(uname -r)Then, to build the driver run the following commands -
cd driver
makeThen you need to load the driver and the device tree overlay into the kernel. You can do so with the following commands
sudo insmod ./led.ko
sudo dtoverlay ledoverlay.dtboNow, your driver should be loaded into the kernel. You can verify it by running the command
lsmod | grep ledYou should see output like this
led 16384 0A file should be created in the path /proc/led.
To turn an LED on/off you need to write to the /proc/led file the index of the led and whether to turn it on or off.
For example, if you wish to turn off LED 0 (which is connected to pin 17) run the command
echo 0,1 > /proc/ledTo turn off LED 3 (which is connected to ping 23) run the command
echo 3,0 > /proc/ledIn a similar manner to controlling the LEDs, in order to read the buttons you need to read the /proc/led file. Every time a button is pressed, its index is written to the file.
If you cat /proc/led you process will sleep until a button is pressed.
If you then press button 0, you should see 0 printed to the terminal.
The actual game logic is in the game directory.
In order to build the game run the following
cd game
makeYou can then start the game by running
./simonTo start playing the game, enter 's', and follow the lights closely!