Arduino Beginner Series: About millis() function
What’s up folks? Hope you had a good time booting your Arduino and running the “Blink LED”program. As mentioned in my previous post, although, your program will run smoothly, its not a good practice to use delay() in your code since it completely stops arduino for that interval time. So before we go and check out how to run the code alternatively, I want you to understand one important function in Arduino library which is millis()
What is millis()
millis() returns the number of milliseconds since the arduino board began running. This number will go back to its original value, which is zero after approximately after 50 days which simply means that if you keep your arduino running for 50 days, you will have a problem using this function but seriously guys! Arduino running for 50 days!!! Hah…
The parameters which it takes are “None” and it returns the number of milliseconds and hence logically the data type (Variable) to use here is “unsigned long” Please note here, if you return using integer, it would not work…Well, technically it will but will throw errors…
So lets see a super simple code,
On line number 1, we have declared a unsigned long data type, the thing which i mentioned earlier.
You all by no know the basic skeleton of an arduino sketch, if you don’t then I recommend you to read my previous post on Blinking an LED
I want to tell you about line no. 5: Serial.begin(9600); We want to display the code results on serial monitor at the baud rate of 9600 and thats why we write that function. If you want to learn more about the Baud rate, check out here – http://www.pccompci.com/Baud_Rate.html
Line no.10 & 11: We want to take the input as current time and print the time since the program started USING the millis() function and that’s what we are doing in line 10 and 11.
Line no. 14 & 16 is super important since if we dont have that line, the program would go mad and start throwing values at crazy speeds and we want to format the program so that the values appear on next lines and thats where the function Serial.printIn(time); comes into picture WITH a delay of 1 second or 1000 milliseconds. (Yes, we are using the delay here but just for representative purpose to show the functioning of millis function)
Well, that’s it, compile it, upload and have fun printing the time values on the serial monitor.
Arduino beginner series tutorials: Blinking an LED
So you got your brand new Arduino and are super excited to fire it up but there is one small problem, you have never written a single line of code in your life…No worries, that’s what Arduino is for! Infact, I love the analogy which Massimo Banzi – one of the creators of Arduino uses, it goes something like this,
“Mostly used by Punk bands – you learnt C major, F Major and G Major chord, Now go write/compose that insanely amazing song!”
Arduino was designed for creative people like you who have the idea and want to quickly prototype it and don’t want to depend on pesky hardware guys, with just a few basics, you can prototype your crazy idea and feel at the top of the world
So without wasting more time with my jargon, lets go ahead with the first super cool program, “Blinking an LED”
If you haven’t downloaded the Arduino IDE for your respective OS, you can go here and download – http://arduino.cc/en/Main/Software
Let me first show you the whole code as it would appear on your Arduino IDE (Integrated Development Environment) and then will break it down line by line,
For convenience, I am not pasting the line by line code,
From line 1 to line 5, I have used cryptic syntax, something like this /* and end with */ well thats the way, one writes multiple line comments, comments are an inherent part of every code. If you want to be a GREAT programmer? ALWAYS COMMENT, Yes, ALWAYS! so that other programmers who are checking your code, it becomes more sensible/readable and understandable.
On line 7, the code reads, int ledPin = 13;
The number 13 corresponds to the digital pin 13 on Arduino board and since we want the LED (Inbuilt LED or an external LED which has the positive end inserted in pin 13 AND the negative i.e the shorter end inserted in ground) to blink, we define it as ledPin = 13 with a syntax of ; Now, remember, every line should end with ; or your program will simply not compile. Well, that’s how the syntax is. You must be wondering, what is “int” Int is simply an “Integer” variable. If your need more indepth reference on what are the different types of variables, you can check in here – http://en.wikipedia.org/wiki/C_data_types
I guess its an easy journey till here, isn’t it? Now lets go ahead and understand the rest of the code. Any arduino code is basically divided into two parts,
void setup() and void loop()
void – Return Value
setup – Procedure name
() – input values
similarly for void loop ()
void – Return Value
loop – Procedure name
() – input values
To understand the analogy of void setup(), umm let me explain by giving you a real world example,
The above was the process of transforming from a loser to a rockstar. The name of the process is “Become a rockstar” it uses “Super loser” as an input and returns “Rockstar”. The two brackets { and } are opening and closing brackets and all the code goes between them. Now, whats void? void is nothing but returning nothing. That’s how these geeks wrote the code man, I din’t…
Hope everything is clear till now with the above rocking example. Lets move ahead to void loop()
As the name suggests, this part of the program loops the code which is between the brackets infinitely and returns void. The line no.16 says, digitalWrite (ledPin, HIGH);
digitalWrite is a command for ledPin which is inserted at pin 13 to turn ON. In Arduino language, thats written by all caps, HIGH and line no. 18 says, digitalWrite (ledPin, LOW); Can you guess whats that? Yep, the LED will be turned off by that line of code.
The last concept is delay(1000); which is line 17 and 19. Pay close attention to this one. delay simply shuts down the whole Arduino microprocessor events for a period of 1 sec or 1000 milliseconds.
Procedure name: delay
Input values: 1000
I guess that’s it, the whole code is ready to be compiled and uploaded using the upload button. Upload and enter the world of Arduino…
One last thing: In my next post, I will explain why one should not use delay function and the disadvantages of the same. Well, till then, if you like this post, do share and if you hate it, you can throw a li’l shit at me by emailing me at shreekantp@yahoo.com
Simple solution to Auto Layout on iOS Versions prior to 6.0 ERROR in Mac OSX 10.7 and later
For time immemorial, I have been getting this feeling of being talentless and wasted after completing my Bachelor in Pharmacy and a fuckin’ stupid MBA. At the same time, my love for iOS apps, Object oriented programming and physical computing was increasing by leaps and bounds and hence I decided to dive – head first into the world of programming without any prior experience.
I am a complete newbie and was learning to code and compile the apps on my Macbook on XCode 4.2 and Mac OSX 10.6.8 until XCode starting messing with my macbook and was slowing and hanging the computer so I decided to buy a Macbook pro and installed the new XCode and fired up a simple code to learn some delegation and to my horror. I was getting these errors,
I checked the code, everything seemed super smooth, interface, implementation but still repeated errors and then figured out a simple solution,
1. You need to click on the left hand menu and select your XIB file,
2. On the right hang side of your XCode window, click on “Show the file inspector button”, scroll down and UNCHECK the ” Use Autolayout” box!
That’s it folks, you can now enjoy your LIFE to the fullest by going back to your previous life of same familiar compiling environment without any hassles!
This is not Freedom!
Scene 1
Father: Son, you should definitely take up science, cause science is the way of life, Its science which is going to change India, its science which is going to take India ahead and make it a super power.
Son: Yes, I will dad, I believe in science, I believe in progress, I believe in education, I will study science and take India to its peak.
After 8 years
Father: Son, of course you know that India is growing at the rate of 8.5%, I agree the growth was slow in the last 2 years but still we are growing, our purchasing power parity has taken us to be the 3rd largest in the world. PIGS (Portugal, Italy, Greece, Spain) have fallen, maybe the whole of Europe will soon, but India will stay strong, India is here to stay, it will grow. You should totally learn business. Maybe from a foreign university, so that you get to know how they differ, use that knowledge and beat them at their own game?
Son: I totally agree with you dad, Science coupled with Business is way to be, moreover, learn how they do it and use those analytics in my business, that’s how I am gonna do it and grow my business when I come back to India. Maybe that’s what everybody should do!
Scene 2
India shining – Yea, can see hard working woman’s face as a reflection on the utensil which she washed with water which she got it from another village which was 30 kms away.
India rising – Godmen stacking $2 million in their holy bedrooms, for emancipation of the poor!
Sun shining on India – With 25 million blind population, more than 3/4 uneducated, since they are forced to drop out of school since they are short of Braille books. Reason – Braille printer needs repairs. State government not interested in spending Rs. 25,000 on the repairs.
Equal India – After more than 60 years, Rajasthan’s dalit women perform rituals with upper caste Hindus at Vishwanath temple and consider it to be the emancipation of the highest sort!
Free India – A woman is constantly sexually harassed at work, a young foreign student is scanned and eve teased even in the so called safest city of Mumbai, women are treated as commodities.
Is a nation which doesn’t respect women, doesn’t treat disabled with equal eyes a free nation?
Dad: But maybe, we should just focus on the good and let the government do its job
Scene 3
A Rebel is born
Insecurities – Just another day in the life of an entrepreneur
After scavenging the streets of Lamington road, Mumbai, India after about a decade wearing my favorite Adidas and a college backpack, I was already feeling like a bumpy college kid! My college bag was full of the following items,
1. Solering Iron
2. Solder stand
3. Solder wire
4. Multimeter
5. Breadboards
6. Nose pliers
7. Stripper (No – human stripper can’t fit in my bag)
8. Male burg strip
9. Couple of LM324′s
10. Resistance box
11. Capacitor box
and finally my Macbook with Arduino DIY stickers! Phew! Suddenly, I saw a train rushing onto platform no. 2, somehow squeezed myself into the so called elite first class compartment and stood still, thinking about how the day was amazing, I totally loved the shopping list and was excited to read about basics of C and embedded C. Suddenly, my status quo was disturbed by a loud obnoxious guy speaking on his not so cool Blackberry,
Loud obnoxious guy: Arre bhai, bola na aapko paisa mil jaayega (Dude, you will get your money)
Some pissed off guy at the other end of the line: Aap chaar mahine se yahi bol rahe hain ( You have been saying this for the past 4 months)
Loud obnoxious guy: Haan, lekin abhi mere boss se approval mil chuka hain aur market bhi down tha, paisa aapko yeah mahine main pahuch jaayega (Yea, but Ive got the approval from my boss and moreover, the markets were down, you will definitely get the money this month)
Some pissed off guy at the other end of the line: Agar mujhe paisa nahi mila tou bahut bura hoga! (If I dont get the money, then you would be in trouble for sure!)
Loud obnoxious guy: Patel bhai, aapko paisa mil jaayega, tension matt lo, ab main phone rakhta hun (Patel bhai, please be tension free, you will get your money but now I need to hang up)
When he hung up, he realized that the whole compartment was staring at him. He pretended as if, he was not the one! Finally, there was silence for sometime, however now thanks to that silence, I could hear another conversation right next to me between a pretty girl and an ugly boy!
Pretty girl: I am 24 and my parents are really getting on my nerves, every single day, they ask me to have a look at a photo of a boy!
Ugly boy: —–Long prevailing silence——
Pretty girl: You don’t wanna marry me, right, you just wanna have fun…(There was a giggle around the compartment)
Ugly boy: (Realizing that he needs to speak up) – Thats not the case Preety, I simply can’t marry now, I am not even an MBA, I am earning just Rs, 10,000, how can you expect me to marry you now?
Pretty girl: (Almost in tears) – So you have to forget me!
Ugly boy: Listen its Bandra, We need to get down!
Enter Bandra – the conversation was over and so was the rush!
I was hanging at the door of the local train with Eric Johnson playing on my iPod (please don’t imitate this action, Ive been doing so for the past 12 years and am a expert), the breeze was flowing on to my mind and I had a seed for my thought, Insecurities!
I wonder, do Mumbaikars stop traveling my local trains for the fear of some terrorist attacks?
Does ISRO not stop working on PSLV for the fear of the satellites dropping from the orbit?
Does the Indian army scared of any potential attack from China or Pakistan?
What if Pakistan attacks India with some nuclear weapon or maybe a biological one? Would it attack Mumbai first? Does India stop working because of this insecurity?
My trusted and hard working product guy is researching on PWM and working with mains, does the thought of electric shock stop him from not working on the research project?
Have been playing the guitar for almost 10 years now and i still don’t have a single original with a band, should I quit and start playing in cover bands?
Ive been a failed entrepreneur all my life, does the thought of failure probe me to quit my startup?
The train had touched Andheri and my life was going on, probably, one step closer to success…
Handling rejections – Just another day in the life of an entrepreneur!
The time was 8.00 am in my watch, the day was bright and unshaven. I was determined and totally prepared for my 60-minute cardio workout. After successfully finishing my time on the treadmill, I was moving to the Exercycle, when I met my personal trainer. I could sense that he wanted to talk to me other than the usual protein, glutamine and “how to get those 8 pack abs”. Apparently, he had a fight with his employer and he was not been treated well by his employer (He was the head trainer and has been loyal to the same gym for 9 years, yea – 9 fricking years!). The conversation was something like this,
Personal trainer: Hi Shreek, please can you do something and try to get $250,000 for starting a new gym, I will take care of everything and see to it that the gym beats every competitor in this geographical area.
Me: (Pondering to myself): My company makes $250,000 revenue after a 2-year stint. Even if I had money, would I invest in a traditional business like this, oh god what’s happened to me, why am I thinking like a bloody tech. investor?
Me: Sir, I don’t have that kind of money but the day I do have that money, I will straight away invest however right now I will have to pass…
The trainer obviously got the vibes and he left, I continued with my exercycle, thinking, how would he be feeling about this rejection, I was watching him from the glass and I could see a little pain on his face however, after about 5 minutes, I found him alright and he continued his job as if the conversation never happened.
The time was 12 noon, It was the time for a conference call with an investor, investor made us wait for 15 minutes over the phone till we decided to hang up since I had to get on a call with our long term client, after about 30 minutes, I get an email from the investor apologizing for the delay and to get on a call immediately if possible, which I obliged. After explaining about our company for about 30 minutes, the investor hung up saying, he can comment more after seeing the financials, which was again a euphemism for a “NO”. I felt a bit bitter, however being a sales guy, rejections had been a part of my everyday life! Maybe I felt bad because I felt in someway that it was the bad karma being rebound to me because of the rejection of the proposal made by the personal trainer in the morning, I needed a break – so I interviewed a prospective employee and gave him a job! There was still something which was hitting me at some corner of my brain and thats when I realized the first lesson on rejection,
1. Rejection is not personal: Entrepreneurs shouldn’t ruin their day because of a simple “NO”. Remember its not about “YOU” being personally rejected, in fact the moment, you get a rejection, it means you are one step closer to a “YES”
After a small break, which consisted of a great meal at a restaurant and beautiful women at the restaurant, I wanted to get back into action, which is what I did,
2. Move on: Yes, that’s right, pick up that phone, call the next client/investor/girl and move on in life – personal or professional. I feel, life is all about numbers. When I run a online CPM campaign, the click through ratio on the campaigns is on an average 0.1. Man, which means only one out of 100 people who see the ads click on it. Love it! I hope you got the point!
3. Knowledge is power: Most of times, rejection might mean that the other person is simply demanding for more information and it is the next step, a step closer to a “YES”. Maybe in my case, the same thing had happened, the investor had demanded for the updated financials! This is especially true when the client is more detailed oriented and to take a more calculated decision, he needs more information from you, which is what you will furnish when asked! umm- I guess, here I will write, “Applied Knowledge is power”
4. Be positive, ALWAYS!: Positivity dwells in people who have the courage to face rejections, yea, endurance comes when the mind and body tries to go that extra mile. Did you know that J.K.Rowling had faced rejections from various publishers for one year. Some pubs, din’t even bother to open her proposal letter, that’s life but we all know who J.K. Rowling is now, thats life again!
5. Ponder,analyze, improve: Self criticism and improv. is the key to every question. Learn from every meeting, denial, experience (good/bad), take mental notes and try to feed them in your grey matter forever!
The time is 11.46pm, looking back, it feels a total roller coaster ride, however that reminds of one of my fav. bands song – watch it, I am sure, you will love the video and song too!
25 Motivational quotes to pump up your entrepreneurial spirit
I know this is really cliche but hey, isn’t it the fact of life, we all love motivation and Entrepreneurs love motivational quotes, don’t they? Motivation is the fuel which pumps their everyday life. It keeps them going when the going gets tough and this is the main reason, I thought, I should write my first blog post on the same. In fact, I am so moved by motivational quotes is that I am thinking of getting the best one tattooed on my chest, yea, that’s what I will do.
These are just some of them, don’t forget to add some in the comments and lets pump up the entrepreneurial spirit.
1. “It’s a lifestyle – train like there’s no finish line.” – Anonymous
2. “If it is important to you, you will find a way. If not, you’ll find an excuse.” – Anonymous
3. “Be proud, but never satisfied.” – Anonymous
4. “If you always do what you have always done, then you will always get what you have always got.” – Anonymous
5. “It’s not the size of the dog in the fight but the size of the fight in the dog” – Magic Johnson, NBA Star
6. “Pain is temporary, pride is forever – Anonymous
7. “Make the most of yourself, for that is all there is of you.” – Ralph Waldo Emerson, Philosopher & Writer
8. “Try and fail is the manner of losers; try and learn is the way of the strong.” – Anonymous
9. “Suffer the pain of discipline or suffer the pain of regret!” – Anonymous
10. “Only the weak attempts to accomplish what he knows he can already achieve.” – Stella Juarez Author
11. “If you don’t design your own life plan, chances are you’ll fall into someone else’s plan. And guess what they have planned for you? Not much.” – Jim Rohn
12. “In life and business, there are two cardinal sins: The first is to act without thought, and the second is to not act at all.” – Carl Rahn
13. “Failure will not overcome me so long as my will to succeed is stronger” – Micheal S. Kirby
14. “Do not go where the path may lead, go instead where there is no path and leave a trail.” – Ralph Waldo Emerson
15. “If you are hurt, whether in mind or body, don’t nurse your bruises. Get up and light-heartedly, courageously, good temperedly get ready for the next encounter. This is the only way to take life – this is also ‘playing’ the game!” – Emily Post
16. “The human body experiences a powerful gravitational pull in the direction of hope” – Norman Cousins Author
17. “A business has to be involving, it has to be fun, and it has to exercise your creative instincts.” – Richard Branson
18. “Can anything be sadder than work left unfinished? Yes; work never begun.” – Christina Rossetti
19. “Destiny is not a matter of chance, it is a matter of choice; it is not a thing to be waited for, it is a thing to be achieved.” – William Jennings Bryan.
20. “That which does not kill me makes me stronger” – Friedrich Nietzsche, Philosopher, Poet, and Classical Philologist
21. “Watch, listen, and learn. You can’t know it all yourself. Anyone who thinks they do is destined for mediocrity.” – Donald Trump
22. “Fall down seven times, get up eight” – Chinese proverb
23. “There is nothing we cannot live down, rise above, and overcome.” – Ella Wheeler Wilcox
24. “Success must be felt within before it can be seen on the outside.” – Unknown
25. “There are plenty of difficult obstacles in your path. Don’t allow yourself to become one of them.” – Ralph Marston, Author and Publisher of The Daily Motivator




