The code is quite simple. Here it is:

]]>The colors appear diffused in the video, but they are much more vivid in reality. I need to learn how to use my camera properly lol.

No custom circuitry is required. I ordered a color shield and couple of 8×8 matrix LEDs from China (ebay) and got this to work. Here is the parts list:

RGB LED 8*8 Matrix Driver Colors Shield For Arduino – $16.50

Matrix 8×8 RGB LED Full Color Dot Square Display 60x60mm Common Anode Arduino – $3.84

Arduino Uno – I had this already.

Total cost – $20.34

Here is the sketch: https://github.com/rmadhuram/ChristmasScroller

I ran into one limit when I tried to add more phrases. If I added more than 4, it kept crashing and random LEDs would light up. I then figured there was a 2K data limit on the character strings you could have in your sketch for Uno!

Wish you all a merry Christmas!

]]>I was not content with the NXT 2.0 text and the graphic it printed using the Mindstorms visual environment. So I flashed LeJOS and wanted to do some more interesting patterns. First up was Lissajous figures. Lissajous figures are generated when you make the velocity of the X and Y motors sinusoidal. We played with different frequencies and velocities. It was very simple to program, and yielded decent results (the videos I took are stuck in a thumb drive which I left at home – pics & videos sometime later).

Then I wanted to do something more exciting, and coded it to trace the Hilbert Curve. Here are the results:

]]>\(2^{n}-1 = (2^{\frac{n}{2}}+1)*(2^{\frac{n}{2}}-1)\)

\(= (2^{\frac{n}{2}}+1)*(2^{\frac{n}{4}}+1)*(2^{\frac{n}{4}}-1)\)

\(= (2^{\frac{n}{2}}+1)*(2^{\frac{n}{4}}+1)*(2^{\frac{n}{8}}+1)*(2^{\frac{n}{8}}-1)\)

If \(n=2^{k}\), where \(k \in Z\)

\(= (2^{\frac{n}{2}}+1)*(2^{\frac{n}{4}}+1)*(2^{\frac{n}{8}}+1)*(2^{\frac{n}{16}}+1) … (2+1)(2-1)\)

\(= \prod_{i=1}^k (2^{\frac{n}{2^i}}+1)\)

This is incredibly cool!

So,

\(2^4-1\) = 15 = 5 x 3

\(2^8-1\) = 255 = 17 x 5 x 3

\(2^{16}-1\) = 65535 = 257 x 17 x 5 x 3

\(2^{32}-1\) = 4294967295 = 65537 x 257 x 17 x 5 x 3

It is fascinating to see the above results in binary:

11 101 x ------ 1111 =

11 101 x 10001 x -------- 11111111 =

11 101 x 10001 x 100000001 x ----------- 16 1's =

Primes of the form \(2^{n}-1\) are called Mersenne primes. Primes of the form \(2^{2^{n}}+1\) are called Fermat primes. The numbers 3, 5, 17, 257 and 65537 are the only known Fermat primes!

That concludes my random rant. Have fun with \(2^{n}-1\)!

]]>Let us invert the problem and try to divide the grey space (0 to 255 each rgb component) into 15 equal intervals.

Each of the component will then be equal to 255/15. First surprise – turns out that 255 is divisible by 15, and equals to 17.

255 = 15 x 17 (recall (n+1)(n-1) = n^2 – 1)

So, each shade of grey = 17*i, where 0<=i<=15
In base 16,
(17*i)_{16} = (16i + i)_{16} = (ii)_{16}

So we would have two repeating digits in base 16: 00, 11, 22, 33 .. ee, ff

For every 17 point step in decimal, we do a 11 step in hex. Very cool! So it does turn out that by writing shades of grey with repeated hex values indeed partition the grey space equally!

Another easy observation is that when we subtract two subsequent repeated digits in base 16, we end up with 11_{16}.

See the Pen HlJie by Raj Madhuram (@rmadhuram) on CodePen.

]]>I was casually looking for properties of the number 2014 this morning, and stumbled on to this neat property:

http://oeis.org/A083074 – n^3 – n^2 – n – 1.

When I looked up for n, a pleasant surprise! It was 13. Hence,

2014 = 13^3 – 13^2 – 13 – 1.

My friend Suneet noted that it can also be written as:

2014 = 13^3 – 13^2 – 13^1 – 13^0

Pretty neat! With some more factorization, we get

2014 = 13(13(13-1)-1)-1

Wish you all a very happy new year 2014!

]]>- Prawns, cleaned and deveined – 1 lb (~500gms) – Costco 21/25 ct works best, or anything is fine.
- Turmeric Powder – a pinch
- Chili Powder – 1 tsp
- Coriander Powder – 2 tsp
- Ground Pepper
- Cilantro (Coriander leaves)
- Curry Leaves – 1 Sprig
- Juice from half a lemon (or even less)
- Salt – 1 tsp, or to taste
- Vegetable Oil

First, let the shrimp soak in water with salt and turmeric for about half-hour. I got a tip from Rachel Ray’s show that soaking in the salt water makes the shrimp plump. After that, drain the water and add some chopped Cilantro (this I copied from Yahoo cafeteria chicken :))

Add salt, turmeric powder, chili powder & coriander powder. Freshly grind some black pepper. Add a sprig of curry leaves. Squeeze half a (small) lemon’s juice and pour over a couple of tsp of oil.

Mix all the ingredients and let it marinade for about half and hour.

Fry in a shallow pan. Turn over after a couple of minutes. Keep frying it until it turns golden brown.

It is best served with thin slices of red onions & a wedge of lime. Enjoy!

I wanted to create a progress indicator that would show completed stages in a shade of green. Initially I was thinking of using Raphaeljs, but this task seemed solvable only by using CSS. So here is a simple jsfiddle I came up with showing how it can be done:

]]>I created a Raspbian “wheezy” image, which is a modified Debian image recommended for starters. I wrote the image on the SD card, hooked up my TV with a HDMI cable, connected a Ethernet cable from my router (thankfully there was one open port, and I had a cable lying around), hooked up the keyboard & mouse and powered it up. Bingo! It was exciting to see the linux bootup sequence on the TV and get to the login prompt. I could log in, but after some keyboard difficulty. And then I ran ‘startx’ to bring up the UI. The kids and I were delighted to see the big raspberry image and the UI coming up, but alas, we could not move the mouse pointer and it would not respond to keyboard. It just got stuck! Looking for solutions, I tried many things, but finally figured out it was due to the most common issue with raspberry pi, the power supply! I managed to find a USB charger rated at 0.85 Amps, plugged it in, and voila! everything began to work!

My kids were excited to see the Scratch program that came preloaded. It worked fine, although much slower compared to its PC counterpart. We fired up the web browser. It was really slow, but web pages loaded fine although no Flash. I wanted to see how far I can push this tiny computer. So I ssh into it and quickly setup a LAMP stack. It was exciting to have it serve web pages! Then I installed WordPress on it, and within minutes, had a full fledged blogging system up and running! You can see it in action here: http://geekraj.no-ip.org/. I’ll explain the details of how to setup WordPress in my next post.

Happy Christmas!

]]>- Jingle Bells
- The First Noel
- O Holy Night
- We Three Kings
- What Child is This

Merry Christmas!

Here is the source code if you are interested: https://github.com/rmadhuram/ArduinoChristmasTunes

I used these components from the OSEPP ARD-101 “Arduino Basics” kit I picked up at Frys.

- Arduino Uno R3
- R1: 10 K ohms
- R2 – R6: 330 ohms
- LED1, LED5: white, LED2, LED4: green, LED3: red
- J1: Piezzo Buzzer
- S1: Switch

The hardware setup is very simple. Lines D3-D7 drives LEDs. D8 drives the Piezzo Buzzer. A switch is connected to D2. We connect resistors before LEDs to limit the current and prevent them from frying.

Source: https://github.com/rmadhuram/ArduinoChristmasTunes/blob/master/christmas_tunes/christmas_tunes.ino

There are two modes of operation, continuous and button press mode. If we set it to continuous mode, it keeps cycling through all the tunes automatically. The global variable **continuousMode** should be set to 1 for it to operate on the continuous mode. If it is in button press mode, and we detect a key press, we play the current tune.

We have a global variable **toneNum** that keeps track of the tune being played. It cycles through 0 to 4. There are also 4 light effects available. We select a random light effect and play it before and after the tune.

— UNDER CONSTRUCTION —

]]>