I happened to see a ruby library called Blinkenlights, which helps to control the three LEDs (Caps lock, Scroll lock & Num lock) on keyboards. I have written few simple programs to play with the keyboard LEDs - basically simulation of three experiments I did in my Digital Electronics lab - Binary Counter, Ring Counter & Johnson Counter.
sudo gem install blinkenlights
A counter that counts from 0 to 7 in binary, using the three LEDs as three bits. 0(000) - All LEDs will be turned off, and 7(111) all of them turned ON. counter.rb
super user privilege is required to access the keyboard, so run it as
sudo ruby counter.rb
Starting with 4 (100), we right shift to get 2 (010), again right shift to get 1(001), and then start over again with 4. This causes the keyboard LEDs to turn ON and then OFF one by one.
This is the Johson counter sequence : 000,001,011,111,110,100,000,001,...