Introduction: Standalone Arduino StopWatch - SainSmart LCD Keypad Shield
So, for my first Instructable, I'll also share with you my first project: A Standalone Arduino StopWatch.
I must admit that this wasn't FULLY created by me. I took the idea of another stopwatch where you read the info on the serial port and then changed it to use the Sainsmart LCD Keypad Shield.
The original project, which needed electronic assembly can be found here.
So, being my first project, I learned A LOT about programming in C (I have a few basic knowledge of programming, but thats it). Knowing there are a lot of guys with the same issues as me, I commented the HECK out of this code (and even included some redundancies on purpose, to explain the concepts further). I hope all the pros here will forgive me, but it's also a way for me to know if I got things right when you all review it :P
So let's get down to business!
- Arduino Uno or equivalent (that fits the Shield);
- Sainsmart LCD Keypad Shield;
- Aditional power source (I use this) - optional.
I'm assuming you already know how to upload sketches to your Arduino.
Connect the shield and upload the code.
Use your external battery (or USB connection) to power the Arduino and have fun!
If you reviewed the code, you will note commented redundancies, as well as LOTS of commenting.
I did this to explain some stuff that I had to find out for myself.
I hope the n00bs (like me :D) will find it helpfull.
Buttons on the Shield:
I found online 2 ways to use the shield's buttons:
The first one uses conditions to find out which button is being pressed.
The second one actually defines the buttons.
For clarity, I used the first one, as I think is easier to follow up how the numbers are calculaded (check the code on the first link).
On my sketch I used the line: "if (x < 600 && x > 400)", unlike the original one on the link, so that ONLY the intended button works, not any other.
You can re-write the program to the second option if you like, it will help you understand further programming in C.
To be honest, I haven't completely understand how the Arduino takes a number between 400 and 600 and categorizes it as the LEFT button, anyone care to explain? :D
The millis() function:
As I understand, you can't make the clock start counting ONLY when you press the button. It starts right away when the Arduino is turned on and the program starts running (press SELECT before starting the counting and it will return the elapsed time since it's on). The millis() function is called and stores that time into a variable when you start counting (so it knows when it started) and when you want to see the elapsed time (so it knows when it "stopped") and does the math from there.
Nothing special, just thought I'd share this cool finding.
So here's my first project, hope you enjoy, and please, for the sake of my learning curve, make reviews, critics, suggestions! :D