# Chapter 5: An Interactive Shell ## Sample code - Directory: `docs/os-on-arduino/code/05_shell` ```bash uv run pio run -d 05_shell -t upload uv run pio device monitor -b 115200 ``` ## Source code The sketch for this chapter. Click a file name to expand. The code is mirrored automatically from the manuscript repository, so what you see here is always current. :::{dropdown} `src/main.cpp` — 96 lines :icon: code [Open on GitHub](https://github.com/iory/learning-os-from-arduino/blob/main/docs/os-on-arduino/code/05_shell/src/main.cpp) ```{literalinclude} ../../../../code/05_shell/src/main.cpp :language: cpp :linenos: ``` ::: :::{dropdown} `include/os_kernel.h` — 79 lines :icon: code [Open on GitHub](https://github.com/iory/learning-os-from-arduino/blob/main/docs/os-on-arduino/code/05_shell/include/os_kernel.h) ```{literalinclude} ../../../../code/05_shell/include/os_kernel.h :language: cpp :linenos: ``` ::: :::{dropdown} `include/shell.h` — 23 lines :icon: code [Open on GitHub](https://github.com/iory/learning-os-from-arduino/blob/main/docs/os-on-arduino/code/05_shell/include/shell.h) ```{literalinclude} ../../../../code/05_shell/include/shell.h :language: cpp :linenos: ``` ::: :::{dropdown} `src/os_kernel.cpp` — 281 lines :icon: code [Open on GitHub](https://github.com/iory/learning-os-from-arduino/blob/main/docs/os-on-arduino/code/05_shell/src/os_kernel.cpp) ```{literalinclude} ../../../../code/05_shell/src/os_kernel.cpp :language: cpp :linenos: ``` ::: :::{dropdown} `src/shell.cpp` — 186 lines :icon: code [Open on GitHub](https://github.com/iory/learning-os-from-arduino/blob/main/docs/os-on-arduino/code/05_shell/src/shell.cpp) ```{literalinclude} ../../../../code/05_shell/src/shell.cpp :language: cpp :linenos: ``` ::: ## On the board ```{raw} html
kill 1 stops task LED1 and the L LED stops blinking (it stays as it was); exec 1 brings it back. The left half of the matrix (LED2) keeps blinking every 0.5 s throughout. (Filmed with a webcam at 30 fps.)
``` ## In the simulator Without the board, the same firmware running in the {doc}`simulator <../getting-started/simulator>` looks like this. ```{figure} ../_static/sim_ch05_kill.gif :name: fig-ch05-sim :width: 80% With L (LED1) and the left half of the matrix (LED2) blinking, `kill 1` from the shell stops only L, and `exec 1` starts it again. The left half never stops. (Recorded in the simulator.) ``` ## Pitfalls (Collected from reader questions — ask via [GitHub Issues](https://github.com/iory/build-your-own-arduino-rtos/issues).)