A (very) Moody Lamp.

Standard

So I was like very much in love with the weather today. I really like winters, especially winter nights. I have one too many memories to associate winter nights with. What I really like about winters is the change in mood. I become mellow like low hanging fog. I really like the silence of winter nights, I just sit there in my veranda taking small puffs of my poison alone with my own thoughts *Bandeh*. The moodiness of it all is very awesome. So I thought I should compliment this very lonely and moody night with something.

Well technically, it is a very easy, 1 hour coding session. A bit of PWM magic and some basic Android. The heart of it is the awesome Arduino Uno rev3 and RedBear Labs’ Bluetooth Low Energy module. The concept is a home automation device. You put on bluetooth on your phone and enter your room, the mood lamp welcomes you with a personal message and then you can set red, blue, green colors and make your own colors according to your mood… all through bluetooth. The device also acts as a “beacon”… umm I’ll explain this later.

Right now, the weather is very awesome here. There is slight wind blowing and the Psithurism (I learned this word today, it means rustling of wind through trees) is very relaxing. A slight chill on the spine and mellow thoughts oscillating (this is awesome) with every beat. After having a long day, such a relaxation is very welcoming. I just wish if I could have a welcoming partner who could melt in with me and be my mood. What else could be better than colors in such a case. The eternal light of infinite colors that burns inside every memory you have.

Memories are colorful but the colors are mellow, you miss them. “That was some shit I did… *slight sad smile*”. You look at them through different shades. Some memories are blue and sad or you are green with jealousy or maybe yellow with some confused times. It is life. You had someone in your past who understood your every emotion. Who was there when you needed someone the most but now they are just colorful memories. The time gone by… the time you think about on such silent nights. The time when lights were brighter. The “grass”… was greener.

So basically, the design of the mood lamp is very simple.

That blue one is my Arduino Uno. The red one is the BLE Mini from the Labs. The white one is the bread board and that small black one is my Philips Go Gear Raaga (cool shit that is… the headphones that came with it are very awesome, brilliant bass *this sounds very cool*). I studied the implementation of the Android app that you have to download from RedBear Labs’ site (linked above). It is very simple. They have made a service and your app uses that service to communicate with the BLE Mini chip. I tweaked the app little bit and added two seek bars. I’ll show the code:

20131220_003446

PWMSeekBar = (SeekBar) findViewById(R.id.PWMSeekBar);
        PWMSeekBar.setEnabled(false);
        PWMSeekBar.setMax(255);
        PWMSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                byte[] buf = new byte[] { (byte) 0x02, (byte) 0x00, (byte) 0x00 };

                buf[1] = (byte) PWMSeekBar.getProgress();

                characteristicTx.setValue(buf);
                mBluetoothLeService.writeCharacteristic(characteristicTx);
            }
        });

The app (the concept is so cool that I guess I’ll generalize for all my future apps), uses unique commands to control different aspects of the Arduino via bluetooth. The above piece of code defines a byte array called buf. I’ll explain that with the Arduino code later. After setting the byte array, it simply transmits the command. characteristicTx is initialized as one of the services provided by the BLE Mini firmware (I’ll touch on that towards the end).

The Arduino code is very clean too.

#include "Boards.h"
#include <ble_mini.h>

const int pin = 4; // lets stay with pin 4.
const int pinMissed = 8;
byte buf[] = {'N','I','N','J','A'};
int incoming;
const int R = 9;
const int G = 10;
const int B = 11;

void setup() {
  BLEMini_begin(57600); // start the BLE device
  // Serial.begin(57600);
  pinMode(pin, OUTPUT);
  pinMode(pinMissed, OUTPUT);
}

void loop() {
  while(BLEMini_available()) {
    byte cmd = BLEMini_read(); // read command.
    byte toggleState = BLEMini_read();// read 0 or 1.
    byte extraData = BLEMini_read();
    switch(cmd) {
      case 0x01:
        switch(toggleState) {
          case 0x00:
            digitalWrite(pin, LOW);
            break;
          case 0x01:
            digitalWrite(pin, HIGH);
            BLEMini_write_bytes(buf, 5);
            break;
        }
        break;
      case 0xA2:
        switch(toggleState) {
          case 0xA1:
            digitalWrite(pinMissed, HIGH);
            break;
          case 0xA0:
            digitalWrite(pinMissed, LOW);
            break;
        }
        break;
      case 0x02:
        switch(extraData) {
          case 0x00:
            analogWrite(R, toggleState);
            break;
          case 0x01:
            analogWrite(G, toggleState);
            break;
          case 0x02:
            analogWrite(B, toggleState);
            break;
        }
       break;
    }
  }
}

Here we see the concept of unique commands. The commands in the app (after I hacked it) follow a pattern. The first byte is the access byte. It signifies which feature of our mood lamp we need. I have made 3 features. A beacon, which can detect your presence and start communicating with your phone. A incoming/missed call alerter. And a bluetooth controlled mood lamp.

The second byte is the state we want to put that feature in at a given moment. The moment the app connects to the BLE Mini, it sends its presence in the form of:

buf [] = {0x01, 0x01, 0x01};

What this means, according the Arduino above, I should put on the LED on pin 4. It then sends a custom message to the phone. The app shows it as a notification in the status bar. But we cannot send a message every time we light up pin 4. The third byte in the command is meant to control that. Only when it connects, it sets the third byte as 0x01. The “extra data” is meant to control these tiny features of the Arduino.

What I really like about a winter night is the time I get alone with myself. Once in a while, I really like to revisit those long forgotten and deeply buried memories. The slow rumble of the trucks passing by on the highway bring back those cold and harsh nights that I spent in utmost misery *I’m the highway*. And slowly grooving with my poison and the music it all seems a colossal kaleidoscope of colors. Some so harsh and striking that they blind me, some so mellow and sorrowful that I’m filled with emotions. Some so crazy that make me think of all the stupid stuff I did. Some are black, some are silent… and most of them are like the winter night. Deep, dark and mysterious. Those are mine. The moments I had. The colors I have seen. Those are mine.

I remember that girl who was kind enough to hold my hand and ask me who I was. I remember those mellow colors of the evening that her smile would brighten. I remember that red color of her irritation, the cool teal color of her touch. The maroon of her unsaid words. The bright yellow of the sun on her face. The gray of her sad smile. *no… only she and nothing else matters*.

I feel the blue of her absence. I feel the green of my envy if she ignores me. I feel the playful orange of her laughter when I hear voice on my phone. I feel the purple of my longing, craving for being with her. I feel the violet of my helplessness of loving her.

I’ll put up my rendition of the Labs’ Android app on Git soon. As another example, I’ll explain how I managed to add the missed call/incoming call alert feature.

telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);     
        telephonyManager.listen(new PhoneStateListener() {

            @Override
            public void onCallStateChanged(int state, String incomingNumber)
             {
                     //  React to incoming call.
                     // number=incomingNumber;
                      // If phone ringing
                     if(state == TelephonyManager.CALL_STATE_RINGING)
                     {
                         byte buf[] = new byte[] { (byte) 0xA2, (byte) 0xA1, (byte) 0x00 };
                         characteristicTx.setValue(buf);
                          mBluetoothLeService.writeCharacteristic(characteristicTx);
                     }
                       // If incoming call received
                     if(state == TelephonyManager.CALL_STATE_OFFHOOK)
                     {
                         byte buf[] = new byte[] { (byte) 0xA2, (byte) 0xA0, (byte) 0x00 };
                         characteristicTx.setValue(buf);
                          mBluetoothLeService.writeCharacteristic(characteristicTx);
                     }

                     if(state == TelephonyManager.CALL_STATE_IDLE)
                     {
                         // do something here
                     }
              } 
        }, PhoneStateListener.LISTEN_CALL_STATE);

I used the Telephony Manager class. I listen to the current call state and set the appropriate commands. If there is an incoming call, the command byte is set to 0xA2 which maps to controlling of pin 8 on the Arduino. If the user answers the call, the light is unset notifying that the user has attended the call. Else, if the user did not attend the call or dismissed the call, it is a missed call and the LED will keep on glowing.

The slight chill of the winter night makes you think about yourself. You are one with yourself *Journeyman*. You think about the sea green memories of your mistake. You think about the bright brownish streaks of the things to come. You feel the pink of the love your soul-mate.

The cold low lying fog cries light gray tears of that faded love for someone once very close to your heart. The black sky makes you think of all those times when you were alone and desperate. And the white spiral of the smoke from my burning poison reminds me of that one forgotten day where, once, I had nothing and no one. Each memory I have has a different color with it. Some good and worth seeing once again and some are so grotesque that I’d never bother to see them again.

Those are my experiences the different shades of life that I have seen and what is better than a moodily lit room where I lie alone with my thoughts on a cold winter night.

The following are the pics of my functioning mood lamp. I’ll put up a video too tomorrow along with the Android app.

20131220_021624 20131220_021604 20131220_021530 20131220_021332 20131220_021156 20131220_021104

Well that was quite cool and well executed. It was a fun project. Something I could play with using my phone. Next step would be to implement something better. I’ll work on interfacing an OLED display panel that will display a welcome message and all your notifications and let you play with LEDs to set your mood and many other good stuff. A whole room controlled by bluetooth in your phone.

May the force be with thee and all the memories you have.

D.

UPDATE: you can find the app here. Make sure you have Android 4.3 or higher as Bluetooth Low Energy is only supported by Android 4.3 or higher.

My musical journey: Starting from Lacuna Coil to my Black Pearl and heavy metal

Standard

One of my friends asked me why is my blog called `comps”music”andstuffs’ if there is not anything musical about it. Right he is, I haven’t posted anything about my music. So this is my first blog post on my evergreen and eternal love: Music.

Music attracted me since I was a kid. My mom heard from her friend about this very renowned music teacher, Guru Thyagarajan. Her friend said that he can come to our home and teach. So mom asked me to join this music class to learn to play some instrument and since I was in fourth grade at that time, didn’t argue much. So the teacher came and he asked me to buy a synthesizer. Told me that it would help me to recognize and memorize how a particular note sounds. So I got my first musical instrument, a Casio SA-65 synthesizer. It was (is) really awesome and since it was my first instrument, I felt like the king of the world. It stayed with me till my sixth grade (it still is there, but I don’t play it any more) I learned a few songs, some scales and other things. It was good enough for me, I was not at all knowledgeable about music as such.

Then the “bad” days of the secondary school started. I left my musical interests behind me for 3 years. But I did not leave my synthesizer. I used to (and still do sometimes) bring it out from the store room and play it. We changed places and slowly and steadily my synthesizer became more of a memory than a friend. I couldn’t find time to play it and left it and forgot about it.

The “bad” days got over when I reached my eleventh grade. We again moved to a new place. By that time, I chucked away Indian “filmy” music and took up western music. Eminem’s The Eminem Show was the first English album I got after I heard one of my basket ball team-mate rapping. I heard it and liked it but it did not click (no, I like Eminem, he is the real rapper because he raps about life and not about sex, drugs and money). Then I got Bryan Adam’s So Far So Good, liked Summer of ’69 a lot. Then I got Backstreet Boys Greatest Hits Chapter One (suggested to me by Trinanjan and Vikram, my two besties at school). They clicked, not so much but yeah, a bit. I used to listen to this album like twice a day. I memorized each and every song of Chapter One and used to sing it along with them. Nick Carter’s voice was so satiable to my music craved ears. I liked them a lot (not love, just like). Then, when I was still new to our just moved-to place, I met this guy whose name was Mihir. He was also a BSB fan and we used to hang out and make long extended fantasies about how we can sing and become great like Nick Carter and then one day Nick Carter would come and greet us and request us to make him a member of our band.

Mihir got a guitar one day and told me that he has started taking guitar classes. He told me that it is an awesome instrument worth learning. I dropped the idea of buying a guitar because I wanted to buy a new pair of Nike shoes. I got my shoes and was happy. I had some money left on me so I went and shopped for some new albums. I fortuitously purchased Lacuna Coil’s Comalies that day.

I came back to my home and was tired. I put the CD on my CD player and listened to it. Cristina Scabbia’s voice was really relaxing. Then after a few songs, I was feeling alive again and started to like Lacuna Coil. Then suddenly everything went silent and the song that was next played was Heaven’s a Lie. In one simple word, I was spellbound (which incidentally is another of my favourite Lacuna Coil album). The song was heavy, it vibrated each and every molecule of my body. I listened to it like five times in a row. I particularly liked how, after the awesomely eerie starting the heavy music suddenly blasts out. The way the heavy guitars blended with Cristina’s voice cannot be expressed in words. After listening to it five or six times again, I went up to my old man and asked if I could trade my shoes for a guitar. He said I can’t but I can get a guitar if I get good marks in the upcoming exams.

I got good marks in the exam and was presented a guitar. It was a really cheap plywood guitar but nonetheless, it was my first shot at musical salvation. I asked Mihir to teach me what all he learned and he did up to a certain extent. Then after a few days I got a guitar teacher, he taught me for a month or two. He taught me basic chords and how to read tabs and all. He vanished one day and I was left alone to walk on this road. The first thing I did was to look up for online resources to learn guitar. Got some sites and I started practising. By that time, I purchased LC’s Karmacode album. Again, I was blown. Simply blown. “Enjoy The Silence” caught my attention. I looked up for the tabs on the net and found it. It was the first ever song that I actually played and still enjoy playing. I learned it bit by bit and when I mastered it, I played it minus the guitar from the actual song. It felt great, almost like I’m playing alongside Cristina. LC was the first band that actually clicked. I loved it. I loved Cristina’s voice, the heavy guitars and the eerie-ness.

I started liking heavy music so I searched about it. Learned that there is this genre called heavy metal and LC was a part of it. So I decided to devote my ears to heavy metal. The second heavy metal I got was Megadeth’s Peace Sells. I was depressed. Didn’t like it one bit. I have listened to it once and only once since the day I got it. Who knew that Megadeth would be the band that would actually push me to buy an electric guitar. I was still in a very nascent stage as a guitarist so I was practising Green Day and all. I saw that my guitar was not that good so I asked for a new one. Again the same condition had to be met. And yet again, I fulfilled it. Got a new guitar (still plywood it was) better than the previous one. Got an album that constituted of various artists (one of them was LC, so saw that and bought it). The first song was Megadeth’s Symphony of Destruction. Blissful was the heaviness and the speed. I learned the starting riff in like ten minutes. But Marty Friedman’s lead was deadly and I was like blown away by a cannon. I “brought” the best of Megadeth. Every song hit me like a cannon ball. All were so heavy and freaking rejuvenating!!! I asked for an electric guitar, but got an acoustic. This time the guitar was teak-wood and was (is) really awesome.

I named this new guitar Stephanie (the story behind it is a top-secret). She was (is) everything to me. The first song that I played on it was Heaven’s a Lie with the backing track. The acoustic version sounded (sounds) really awesome. I played with Stephanie for like 2 years. But I also developed a certain attraction towards heavy metal. I wanted to play like Dave Mustaine and James Hetfield and other Gods of metal and figured out that this acoustic dreadnaught will only hinder my ability. So again the same criteria had to be fulfilled. This time I did it differently, I published a research paper on bypassing computer firewalls and its defence mechanism. Dad was impressed and gave me the ultimate gift… my Black Pearl. My Ibanez GRG 250 P.

I just got her like two months back, so there is nothing much to share about her. I have moved from being a novice guitarist to a good one. Not that good, but yes, I can play :). These days, I’m practising Megadeth’s Symphony of Destruction’s solo. I’m more focussed on increasing my speed as heavy/thrash/speed metal requires speed. I composed three instrumentals and got not-so-bad comments on them :D.

So this was my musical journey so far. I hope you guys enjoyed reading it.

May the force be with you

Code_ninja