

Since I don't know exactly how long my code takes to run, this allows the arduino to keep time without knowing exactly how many milliseconds it took to run all of the code. This is expressed as the difference of and. When ms is incremented in the first line, it is incremented by the number of milliseconds since the last time the function was called. Ms, seconds, minutes, hours and sinceLast are global variables.Īs you can see, sinceLast is set to the value of millis() in the second line of the function. Here's the function that is called at the beginning of loop() (it's on GitHub in the sidebar in the "time.ino" file, too): Once the time is set, I use the difference in milliseconds between different calls to the function, to keep time. I actually took this code from the example code for the DS1307 RTC, which sets the RTC to _TIME_ if no time is specified. I parse this string and use atoi() to get integer values for hours, minutes, and seconds, which I set in the setup() function. This is a char array with the time of compilation in the format HH:MM:SS. To set the time originally, I use a constant/macro that's in C++ called _TIME_. I explain it in my most recent project log, but I'll expand on it here. I apologize in advance for the horrible formatting comments don't give you options for syntax highlighting and the like. The use of a Nokia battery in your project is pretty cool! I was also originally looking at the Pro Mini to do this project, but the trinket, being a little cheaper, was convenient. From Uno to Trinket: Some Problems davish.This'll be a little tricky since it can't be too bulky. Next thing to do is to make an enclosure and watch strap.
Adafruit trinket pro timer example software#
A video, showing off the new form factor as well as an overview of the software as it stands, is below: It looks pretty similar to the digital clock view, but it's in 24-hour mode and tells you if you're incrementing hours or minutes. The last thing I added was a new mode for changing the time. I wrote a function, adjustInternalTime(), that increments milliseconds using millis() and increments seconds, minutes, and hours accordingly. I parse this string, and set the hours, minutes and seconds to the right value. C++ adds a string constant, _TIME_, that represents the time in HH:MM:SS format. Since the RTC currently isn't integrated, the next thing was to find a way to set the time. After soldering that all together, soldering the ground lead, and bending the wires to "smush" everything together, I had something that resembled a watch: I then cut off the extra board so it would be less than height of the watch, and then soldered leads for the three digital pins to the other side of the switches. I placed them on some PCB from RadioShack (I know, I know), and soldered them in. The next thing to do was to solder on the buttons.

After that, I soldered the backpack back on. This way, the wires don't have to stretch all the way across the board.

In the code, 11 is set to OUTPUT, HIGH and 10 is set to OUTPUT, LOW. I soldered Vin to pin 11 and Ground to pin 10. The reset pin was switched from 4 to 12, since 4 was on the other side of the trinket.

Then, I soldered the SDA and SCL wires to A4 and A5, respectively. First thing I did was cut down the leads on the OLED. Instead of waiting for the step-up regulator to arrive, I decided to put everything else together in a small package.
