Arduino Watch With Nokia 3110 Screen
by kenyer in Circuits > Arduino
107901 Views, 326 Favorites, 0 Comments
Arduino Watch With Nokia 3110 Screen
My goal for this project is to make a watch with selectable dials, stopwatch and millidays.
This idea started with an Aprils fools prank about metric-time. (http://www.youtube.com/watch?v=K35xG1buyFA)
First I wanted to make a metric clock but soon this idea evolved from a metric watch into an open course watch.
I knew that it would be hard (or impossible) to make the watch small enough to really wear, but I wanted to try it anyway.
This would be mostly a programming project, but that is nice for long, cold and dark winter nights.
So my watch needs to be:
This idea started with an Aprils fools prank about metric-time. (http://www.youtube.com/watch?v=K35xG1buyFA)
First I wanted to make a metric clock but soon this idea evolved from a metric watch into an open course watch.
I knew that it would be hard (or impossible) to make the watch small enough to really wear, but I wanted to try it anyway.
This would be mostly a programming project, but that is nice for long, cold and dark winter nights.
So my watch needs to be:
- small enough to wear
- easy to reprogram
- capable of showing metric time
- have selectable dails
- have an easy understandable menu structure
- controllable with just 2 buttons (digital watches with 4 buttons confuse me)
- cheap (I'm still Dutch you know)
You Will Need
For the Watch
Tools and stuff
Wristband
tools and stuff
- Arduino Nano
- Nokia 3110 screen (Adafruit or something)
- 2 pushbuttons
- 2 10K resistors
- some wires
- (optional a thermometer-ic)
- 2 button-cell batteries
- 2 small magnets
- a small breadboard for prototyping if you want
Tools and stuff
- soldering iron
- solder
- desoldering pump (or wick)
- pliers
- usb-cable
- computer with Arduino software
Wristband
- silicon kit (black)
-
buckle (from old watch)
- plank
- aluminum 15 mm x 15 mm L-profile
- aluminum strips and scraps
- screws
- polyester filler
- polyester topcoat
- wax
- superglue
tools and stuff
- screwdriver
- hacksaw
- old credit card
- spatula
- dremel
- grinding stones for the dremel
- sanding paper
- some clean cloth
- rubber gloves
- ruler
- sharpy
Breadboarding the Watch
To check if everything works like I want it to work, I first wire the components up on a breadboard.
I am going to use the library from Adafruit (thank you Lady Ada) to get the screen up and running, so I wire it up like it's written in the test-sketch (program):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
There is also a wire going from pin 9 to the backlight and a wire to ground. Because the display is actually 3.3V instead of the 5V coming from the Arduino, I wired the VCC to the 3.3V power of the Arduino. The power on the data pins is still 5V though, what can kill your screen, but mine is still working. (no guarantees though)
ATTENTION!!! >>> not all Nokia screen break out boards are wired the same way. Read what is written on the board and wire accordingly.
I also wired up two push buttons to pin 10 and 11, with a 10K pull down resistor to ground. (see the picture if you need more info)
In the picture it looks like the 3.3V wire is going nowhere, but that is just because I couldn't find the right part in Fritzing (the program that made this picture for me)
I am going to use the library from Adafruit (thank you Lady Ada) to get the screen up and running, so I wire it up like it's written in the test-sketch (program):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
There is also a wire going from pin 9 to the backlight and a wire to ground. Because the display is actually 3.3V instead of the 5V coming from the Arduino, I wired the VCC to the 3.3V power of the Arduino. The power on the data pins is still 5V though, what can kill your screen, but mine is still working. (no guarantees though)
ATTENTION!!! >>> not all Nokia screen break out boards are wired the same way. Read what is written on the board and wire accordingly.
I also wired up two push buttons to pin 10 and 11, with a 10K pull down resistor to ground. (see the picture if you need more info)
In the picture it looks like the 3.3V wire is going nowhere, but that is just because I couldn't find the right part in Fritzing (the program that made this picture for me)
Programming the Sketch
For the screen I used the Adafruit library so it might be wise to start of with the Adafruit test sketch to check if everything is working. This sketch can also teach you a lot about how to program the screen so you can tweak the watch according to your own wishes.
Here you can find the Adafruit sketch together with the Nokia 5110 library and the GFX library. You will also find instructions about how to install the libraries on this page.
When everything is working you can run my watch-sketch.
[There are still some minor glitches in the code but mostly it works great. For the rest please tweak it how you like it.]
Here you can find the Adafruit sketch together with the Nokia 5110 library and the GFX library. You will also find instructions about how to install the libraries on this page.
When everything is working you can run my watch-sketch.
[There are still some minor glitches in the code but mostly it works great. For the rest please tweak it how you like it.]
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Time.h> //adding the time-library
int knoptijd = 250; //setting all the variables (sorry for the Dutch names)
int uur = 12;
int minuut = 0;
int seconde = 0;
int dag = 1;
int maand = 1;
int jaar = 2013;
int knoplicht = 11;
int knopmenu = 10;
int lichtwaarde = 0;
int menuwaarde = 0;
float milliuur = 0;
float milliminuut = 0;
float milliseconde = 0;
float millidays = 4000;
int tijd = 0;
int milli = 0;
float millitijd = 0;
int oudeseconde = 0;
int ledpin = 9;
int licht = LOW;
int lichtsterkte = 30;
int schermcontrast = 60;
int temperatuur = 0;
int tempsensor = 0;
int plaatkeuze = 1;
int tempteller = 999;
int temppin = 2;
//int minoud = 59;
int kleur = BLACK;
int kleurwis = WHITE;
int breed = 42;
long tussentijd = 0;
long teller = 0;
long tellerStart = 0;
long tussenstand = 0;
int breedMinWijzer[30] ={0,2,3,5,7,9,10,11,13,14,15,16,17,17,17,18,17,17,17,16,15,14,13,11,10,9,7,5,3,2};
int hoogMinWijzer[60] ={6,6,7,7,8,9,10,11,13,14,15,17,18,20,22,24,26,28,30,31,33,34,35,37,38,39,40,41,41,42,42,42,41,41,40,39,38,37,35,34,33,31,30,28,26,24,22,20,18,17,15,14,13,11,10,9,8,7,7,6};
int breedUurWijzer[36] ={0,6,10,12,10,6,1,7,11,12,10,5,2,8,11,12,9,4,3,9,11,11,9,3,4,9,12,11,8,2,5,10,12,11,7,1};
int hoogUurWijzer[72] ={12,14,18,24,30,34,12,15,19,25,31,35,12,15,20,26,31,35,12,16,21,27,32,36,13,17,22,28,33,36,13,17,23,29,33,36,36,36,33,29,23,17,13,36,33,28,22,17,13,36,32,27,21,16,12,35,31,26,20,15,12,35,31,25,19,15,12,34,30,24,18,14};
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
void setup() {
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(knoplicht, INPUT);
pinMode(knopmenu, INPUT);
pinMode(temppin, OUTPUT);
setTime(uur,minuut,seconde,dag,maand,jaar); //setting the starttime for the clock when it starts up
display.begin();
display.setContrast(schermcontrast);
display.clearDisplay(); // clears the screen and buffer
}
void loop() {
temper();
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH) menu(); //if the [menu]button is pusched
setmillidays();
if (plaatkeuze == 1) digitalClockDisplay();
if (plaatkeuze == 2) wijzerpl();
if (plaatkeuze == 3) stopwatch();
if (plaatkeuze == 4) binair();
if (plaatkeuze == 5) classic();
if (plaatkeuze == 6) big();
lichtwaarde = digitalRead(knoplicht);
if (lichtwaarde == HIGH) lichtaan();
delay(1);
}
void lichtaan(){
if (licht == HIGH){
licht = LOW;
analogWrite(ledpin, 0);
}
else{
licht = HIGH;
analogWrite(ledpin, lichtsterkte);
}
delay(knoptijd);
}
void setmillidays(){
milliuur = hour() * 41.6667;
milliminuut = minute() * 0.6944;
if (oudeseconde == second()){
milli = millis() - tijd;
millitijd = milli * 0.0000116;
}
else{
millitijd = 0;
milli = millis() - tijd;
tijd = millis();
}
oudeseconde = second();
milliseconde = oudeseconde * 0.0116;
millidays = milliuur + milliminuut + milliseconde + millitijd;
}
void setklok(){ //setting the clock
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the hours
display.println("");
display.print(" uur: ");
display.setTextSize(2);
display.println(uur);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
uur++;
if (uur > 24) uur = 1;
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the hours
display.println("");
display.print(" uur: ");
display.setTextSize(2);
display.println(uur);
display.setTextSize(1);
display.print("+ ");
display.display();
}
lichtwaarde = digitalRead(knoplicht);
}
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the minutes
display.println("");
display.print(" min.: ");
display.setTextSize(2);
display.println(minuut);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
minuut++;
if (minuut > 59) minuut = 0;
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the minutes
display.println("");
display.print(" min.: ");
display.setTextSize(2);
display.println(minuut);
display.setTextSize(1);
display.print("+ ");
display.display();
}
lichtwaarde = digitalRead(knoplicht);
}
//setting the month
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the month
display.println("");
display.print(" maand:");
display.setTextSize(2);
display.println(maand);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
maand++;
if (maand > 12) maand = 1;
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the month
display.println("");
display.print(" maand:");
display.setTextSize(2);
display.println(maand);
display.setTextSize(1);
display.print("+ ");
display.display();
}
lichtwaarde = digitalRead(knoplicht);
}
//setting the day
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the day
display.println("");
display.print(" dag: ");
display.setTextSize(2);
display.println(dag);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
dag++;
if (maand == 1 || maand == 3 || maand == 5 || maand == 7 || maand == 8 || maand == 10 || maand == 12){
if (dag > 31) dag = 1;
}
if (maand == 4 || maand == 6 || maand == 9 || maand == 11){
if (dag > 30) dag = 1;
}
if (maand == 2){
if (dag > 28) dag = 1;
}
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the day
display.println("");
display.print(" dag: ");
display.setTextSize(2);
display.println(dag);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
}
lichtwaarde = digitalRead(knoplicht);
}
// year
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the year
display.println("");
display.print(" jaar");
display.setTextSize(2);
display.print(jaar);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
jaar++;
if (jaar > 2100) jaar = 2013;
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the year
display.println("");
display.print(" jaar");
display.setTextSize(2);
display.print(jaar);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
}
lichtwaarde = digitalRead(knoplicht);
}
setTime(uur,minuut,seconde,dag,maand,jaar);
delay(knoptijd);
display.clearDisplay();
loop();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
if(digits < 10)
display.print('0');
display.print(digits);
}
void lichtinstellen(){
display.clearDisplay();
display.println("> Sterkte:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(lichtsterkte/10);
display.setTextSize(1);
display.println("");
display.print("+ 1----->25");
display.display();
delay(knoptijd);
lichtwaarde = LOW;
while(lichtwaarde == LOW){
display.clearDisplay();
display.println("> Sterkte:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(lichtsterkte/10);
display.setTextSize(1);
display.println("");
display.print("+ 1----->25");
display.display();
analogWrite(ledpin, lichtsterkte);
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
lichtwaarde = digitalRead(knoplicht);
if (menuwaarde == HIGH){
lichtsterkte = lichtsterkte + 10;
if (lichtsterkte == 260) lichtsterkte = 10;
analogWrite(ledpin, lichtsterkte);
}
}
loop();
}
void contrast(){
display.clearDisplay();
display.println("> Contrast:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(schermcontrast);
display.setTextSize(1);
display.println("");
display.print("+ 45%->95%");
display.display();
delay(knoptijd);
lichtwaarde = LOW;
while(lichtwaarde == LOW){
display.clearDisplay();
display.println("> Contrast:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(schermcontrast);
display.setTextSize(1);
display.println("");
display.print("+ 45%->95%");
display.display();
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
lichtwaarde = digitalRead(knoplicht);
if (menuwaarde == HIGH){
schermcontrast = schermcontrast + 1;
if (schermcontrast == 95) schermcontrast = 45;
display.setContrast(schermcontrast);
}
}
loop();
}
void temper(){
tempteller++;
if (tempteller == 1000){
digitalWrite(temppin, HIGH);
delay(200);
tempsensor = analogRead(1)* 0.4882812;
temperatuur = tempsensor - 273.15 - 31.4; //33 is de correctie doe nodig was voor mijn sensor
digitalWrite(temppin, LOW);
tempteller = 0;
if (temperatuur > 99 || temperatuur < -99) temperatuur = 99;
}
}
void menu(){
display.setTextSize(1);
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("klok inst.");
display.setTextColor(BLACK);
display.println(" wijzerplaat");
display.println(" licht");
display.println(" contrast");
display.println("");
display.print("v terug");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) setklok();
if (menuwaarde == HIGH) menu2();
}
void menu2(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("wijzerplaat");
display.setTextColor(BLACK);
display.println(" licht");
display.println(" contrast");
display.println("");
display.println(" terug");
display.print("v klok inst.");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) wijzerplaat();
if (menuwaarde == HIGH) menu3();
}
void menu3(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("licht");
display.setTextColor(BLACK);
display.println(" contrast");
display.println("");
display.println(" terug");
display.println(" klok inst.");
display.print("v wijzerplaat");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) lichtinstellen();
if (menuwaarde == HIGH) menu4();
}
void menu4(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("contrast");
display.setTextColor(BLACK);
display.println("");
display.println(" terug");
display.println(" klok inst.");
display.println(" wijzerplaat");
display.print("v licht");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) contrast();
if (menuwaarde == HIGH) menu5();
}
void menu5(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("");
display.setTextColor(BLACK);
display.println(" terug");
display.println(" klok inst.");
display.println(" wijzerplaat");
display.println(" licht");
display.print("v contrast");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
// if (lichtwaarde == HIGH) nogOnbekend();
if (menuwaarde == HIGH) menu6();
}
void menu6(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("terug");
display.setTextColor(BLACK);
display.println(" klok inst.");
display.println(" wijzerplaat");
display.println(" licht");
display.println(" contrast");
display.print("v");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH){delay(knoptijd); display.clearDisplay(); loop();}
if (menuwaarde == HIGH) menu();
}
void wijzerplaat(){
lichtwaarde = LOW;
menuwaarde = LOW;
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("millidays");
display.setTextColor(BLACK);
display.println(" wijzers");
display.println(" stopwatch");
display.println(" binair");
display.println(" classic");
display.print("v big");
display.display();
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("millidays");
display.setTextColor(BLACK);
display.println(" wijzers");
display.println(" stopwatch");
display.println(" binair");
display.println(" classic");
display.print("v big");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 1;
loop();
}
if (menuwaarde == HIGH) wijzerplaat2();
}
void wijzerplaat2(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("wijzers");
display.setTextColor(BLACK);
display.println(" stopwatch");
display.println(" binair");
display.println(" classic");
display.println(" big");
display.print("v millidays");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 2;
// minoud = 61;
display.clearDisplay();
loop();
}
if (menuwaarde == HIGH) wijzerplaat3();
}
void wijzerplaat3(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("stopwatch");
display.setTextColor(BLACK);
display.println(" binair");
display.println(" classic");
display.println(" big");
display.println(" millidays");
display.print("v wijzers");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 3;
loop();
}
if (menuwaarde == HIGH) wijzerplaat4();
}
void wijzerplaat4(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("binair");
display.setTextColor(BLACK);
display.println(" classic");
display.println(" big");
display.println(" millidays");
display.println(" wijzers");
display.print("v stopwatch");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 4;
loop();
}
if (menuwaarde == HIGH) wijzerplaat5();
}
void wijzerplaat5(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("classic");
display.setTextColor(BLACK);
display.println(" big");
display.println(" millidays");
display.println(" wijzers");
display.println(" stopwatch");
display.print("v binair");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 5;
// minoud = 61;
display.clearDisplay();
loop();
}
if (menuwaarde == HIGH) wijzerplaat6();
}
void wijzerplaat6(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("big");
display.setTextColor(BLACK);
display.println(" millidays");
display.println(" wijzers");
display.println(" stopwatch");
display.println(" binair");
display.print("v classic");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 6;
loop();
}
if (menuwaarde == HIGH) wijzerplaat();
}
void binair(){
display.clearDisplay();
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.print(" 1 2 4 8 ");
display.setTextColor(BLACK);
display.print(" ");
display.println(second());
int b1 = 0;
int b2 = 0;
int b3 = 0;
int b4 = 0;
int x = hour();
if (x > 12) x = x - 12;
if(x-8 >= 0){b4=1; x = x -8;}
if(x-4 >= 0){b3=1; x = x -4;}
if(x-2 >= 0){b2=1; x = x -2;}
if(x == 1){b1=1;}
display.print(" ");
display.print(b1);
display.print(" ");
display.print(b2);
display.print(" ");
display.print(b3);
display.print(" ");
display.println(b4);
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(" 1 3 ");
display.println(" 1 2 4 8 6 2 ");
display.setTextColor(BLACK);
b1 = 0;
b2 = 0;
b3 = 0;
b4 = 0;
int b5 = 0;
int b6 = 0;
x = minute();
if(x-32 >= 0){b6=1; x = x - 32;}
if(x-16 >= 0){b5=1; x = x - 16;}
if(x-8 >= 0){b4=1; x = x -8;}
if(x-4 >= 0){b3=1; x = x -4;}
if(x-2 >= 0){b2=1; x = x -2;}
if(x == 1){b1=1;}
display.print(" ");
display.print(b1);
display.print(" ");
display.print(b2);
display.print(" ");
display.print(b3);
display.print(" ");
display.print(b4);
display.print(" ");
display.print(b5);
display.print(" ");
display.print(b6);
display.display();
}
void stopwatch(){
delay(knoptijd);
long tellermini = 0;
long tellersec = 0;
long tellermin = 0;
long tellernu = 0;
while (tellerStart == 0){
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH) menu();
if (lichtwaarde == HIGH) {
tellerStart = 1;
teller = millis();
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println("< start");
display.setTextSize(2);
display.print("00:00");
display.setTextSize(1);
display.println("00");
display.println();
display.println(" lap:");
display.print(" ");
display.println("--:--");
display.print("< menu");
display.display();
}
while (tellerStart == 1){
if (millis() - teller > 250){
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
if (lichtwaarde == HIGH) {
tellerStart = 2;
}
}
tellernu = millis() - teller;
for (int i = 0; i < 100; i++){
if (tellernu > i * 60000) tellermin = i;}
tellernu = tellernu - (tellermin * 60000);
for (int j = 0; j < 60; j++){
if (tellernu > j * 1000) tellersec = j;}
tellernu = tellernu - (tellersec * 1000);
for (int k = 0; k < 100; k++){
if (tellernu > k * 100) tellermini = k;}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println("< stop");
display.setTextSize(2);
printDigits(tellermin);
display.print(":");
printDigits(tellersec);
display.setTextSize(1);
display.print(tellermini);
display.println();
display.println();
display.println(" lap:");
display.print(" ");
display.println("--:--");
display.print("< laptijd");
display.display();
}
while (tellerStart == 2){
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
if (lichtwaarde == HIGH) {
tellerStart = 0;
}
if (menuwaarde == HIGH) menu();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println("< reset");
display.setTextSize(2);
printDigits(tellermin);
display.print(":");
printDigits(tellersec);
display.setTextSize(1);
display.print(tellermini);
display.println();
display.println();
display.println(" lap:");
display.print(" ");
display.println("--:--");
display.print("< menu");
display.display();
}
}
void digitalClockDisplay(){ //printing time and date
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.print("Millidays");
if (temperatuur >= 0) display.print(" ");
if (temperatuur < 10 && temperatuur > 0) display.print(" ");
display.print(temperatuur);
display.write(247);
display.print("C");
display.setTextSize(2);
display.setTextColor(BLACK);
display.println(millidays);
display.setTextSize(1);
display.setTextColor(BLACK);
display.print(day());
display.print("/");
display.print(month());
display.print("/");
display.println(year());
display.setTextSize(2);
display.setTextColor(BLACK);
display.print(hour());
display.print(":");
printDigits(minute());
display.setTextSize(1);
display.print(":");
printDigits(second());
display.println();
display.display();
}
void wijzerpl(){
kleur = BLACK;
kleurwis = WHITE;
breed = 42;
display.drawCircle(breed, 24, 23, kleur);
display.drawLine(breed, 2, breed, 3, kleur);
display.drawLine(breed-22, 24, breed-21, 24, kleur);
display.drawLine(breed, 46, breed, 45, kleur);
display.drawLine(breed+22, 24, breed+21, 24, kleur);
display.display();
wijzer();
}
void classic(){
kleur = BLACK;
kleurwis = WHITE;
breed = 42;
display.setCursor(0,0);
display.println(" XII");
display.println();
display.print(" IX III");
display.println();
display.println();
display.print(" VI");
display.display();
wijzer();
}
void wijzer(){
if (millis() - tussentijd > 5000){ // wait inbetween refreshing
tussentijd = millis();
// deleting the old hands
display.fillCircle(breed, 24, 19, kleurwis);
// placing the minute hand
for (int i = 0; i < 30; i++){
if (minute() == i) display.drawLine(breed, 24, breed+breedMinWijzer[i], hoogMinWijzer[i], kleur);
if (minute() == i+30) display.drawLine(breed, 24, breed-breedMinWijzer[i], hoogMinWijzer[i+30], kleur);
}
// placing the hour hand
for (int i = 0; i < 6; i++){
if (hour() == i || hour() == i+12){
if (minute() < 10){ display.drawLine(breed, 24, breed+breedUurWijzer[i], hoogUurWijzer[i], kleur);}
else{if (minute() < 20){ display.drawLine(breed, 24, breed+breedUurWijzer[i+6], hoogUurWijzer[i+6], kleur);}
else{if (minute() < 30){ display.drawLine(breed, 24, breed+breedUurWijzer[i+12], hoogUurWijzer[i+12], kleur);}
else{if (minute() < 40){ display.drawLine(breed, 24, breed+breedUurWijzer[i+18], hoogUurWijzer[i+18], kleur);}
else{if (minute() < 50){ display.drawLine(breed, 24, breed+breedUurWijzer[i+24], hoogUurWijzer[i+24], kleur);}
else{ display.drawLine(breed, 24, breed+breedUurWijzer[i+30], hoogUurWijzer[i+30], kleur);}
}}}}}
if (hour() == i+6 || hour() == i+18){
if (minute() < 10){ display.drawLine(breed, 24, breed-breedUurWijzer[i], hoogUurWijzer[i+36], kleur);}
else{if (minute() < 20){ display.drawLine(breed, 24, breed-breedUurWijzer[i+6], hoogUurWijzer[i+42], kleur);}
else{if (minute() < 30){ display.drawLine(breed, 24, breed-breedUurWijzer[i+12], hoogUurWijzer[i+48], kleur);}
else{if (minute() < 40){ display.drawLine(breed, 24, breed-breedUurWijzer[i+18], hoogUurWijzer[i+54], kleur);}
else{if (minute() < 50){ display.drawLine(breed, 24, breed-breedUurWijzer[i+24], hoogUurWijzer[i+60], kleur);}
else{ display.drawLine(breed, 24, breed-breedUurWijzer[i+30], hoogUurWijzer[i+66], kleur);}
}}}}}
}
}
display.display();
}
void big(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println();
display.setTextSize(3);
display.print(hour());
display.setTextSize(2);
display.print(":");
display.setTextSize(3);
printDigits(minute());
display.display();
}
#include <Adafruit_PCD8544.h>
#include <Time.h> //adding the time-library
int knoptijd = 250; //setting all the variables (sorry for the Dutch names)
int uur = 12;
int minuut = 0;
int seconde = 0;
int dag = 1;
int maand = 1;
int jaar = 2013;
int knoplicht = 11;
int knopmenu = 10;
int lichtwaarde = 0;
int menuwaarde = 0;
float milliuur = 0;
float milliminuut = 0;
float milliseconde = 0;
float millidays = 4000;
int tijd = 0;
int milli = 0;
float millitijd = 0;
int oudeseconde = 0;
int ledpin = 9;
int licht = LOW;
int lichtsterkte = 30;
int schermcontrast = 60;
int temperatuur = 0;
int tempsensor = 0;
int plaatkeuze = 1;
int tempteller = 999;
int temppin = 2;
//int minoud = 59;
int kleur = BLACK;
int kleurwis = WHITE;
int breed = 42;
long tussentijd = 0;
long teller = 0;
long tellerStart = 0;
long tussenstand = 0;
int breedMinWijzer[30] ={0,2,3,5,7,9,10,11,13,14,15,16,17,17,17,18,17,17,17,16,15,14,13,11,10,9,7,5,3,2};
int hoogMinWijzer[60] ={6,6,7,7,8,9,10,11,13,14,15,17,18,20,22,24,26,28,30,31,33,34,35,37,38,39,40,41,41,42,42,42,41,41,40,39,38,37,35,34,33,31,30,28,26,24,22,20,18,17,15,14,13,11,10,9,8,7,7,6};
int breedUurWijzer[36] ={0,6,10,12,10,6,1,7,11,12,10,5,2,8,11,12,9,4,3,9,11,11,9,3,4,9,12,11,8,2,5,10,12,11,7,1};
int hoogUurWijzer[72] ={12,14,18,24,30,34,12,15,19,25,31,35,12,15,20,26,31,35,12,16,21,27,32,36,13,17,22,28,33,36,13,17,23,29,33,36,36,36,33,29,23,17,13,36,33,28,22,17,13,36,32,27,21,16,12,35,31,26,20,15,12,35,31,25,19,15,12,34,30,24,18,14};
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
void setup() {
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(knoplicht, INPUT);
pinMode(knopmenu, INPUT);
pinMode(temppin, OUTPUT);
setTime(uur,minuut,seconde,dag,maand,jaar); //setting the starttime for the clock when it starts up
display.begin();
display.setContrast(schermcontrast);
display.clearDisplay(); // clears the screen and buffer
}
void loop() {
temper();
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH) menu(); //if the [menu]button is pusched
setmillidays();
if (plaatkeuze == 1) digitalClockDisplay();
if (plaatkeuze == 2) wijzerpl();
if (plaatkeuze == 3) stopwatch();
if (plaatkeuze == 4) binair();
if (plaatkeuze == 5) classic();
if (plaatkeuze == 6) big();
lichtwaarde = digitalRead(knoplicht);
if (lichtwaarde == HIGH) lichtaan();
delay(1);
}
void lichtaan(){
if (licht == HIGH){
licht = LOW;
analogWrite(ledpin, 0);
}
else{
licht = HIGH;
analogWrite(ledpin, lichtsterkte);
}
delay(knoptijd);
}
void setmillidays(){
milliuur = hour() * 41.6667;
milliminuut = minute() * 0.6944;
if (oudeseconde == second()){
milli = millis() - tijd;
millitijd = milli * 0.0000116;
}
else{
millitijd = 0;
milli = millis() - tijd;
tijd = millis();
}
oudeseconde = second();
milliseconde = oudeseconde * 0.0116;
millidays = milliuur + milliminuut + milliseconde + millitijd;
}
void setklok(){ //setting the clock
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the hours
display.println("");
display.print(" uur: ");
display.setTextSize(2);
display.println(uur);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
uur++;
if (uur > 24) uur = 1;
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the hours
display.println("");
display.print(" uur: ");
display.setTextSize(2);
display.println(uur);
display.setTextSize(1);
display.print("+ ");
display.display();
}
lichtwaarde = digitalRead(knoplicht);
}
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the minutes
display.println("");
display.print(" min.: ");
display.setTextSize(2);
display.println(minuut);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
minuut++;
if (minuut > 59) minuut = 0;
display.clearDisplay(); // clears the screen and buffer
display.println("v tijd");
display.println(" instellen"); //setting the minutes
display.println("");
display.print(" min.: ");
display.setTextSize(2);
display.println(minuut);
display.setTextSize(1);
display.print("+ ");
display.display();
}
lichtwaarde = digitalRead(knoplicht);
}
//setting the month
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the month
display.println("");
display.print(" maand:");
display.setTextSize(2);
display.println(maand);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
maand++;
if (maand > 12) maand = 1;
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the month
display.println("");
display.print(" maand:");
display.setTextSize(2);
display.println(maand);
display.setTextSize(1);
display.print("+ ");
display.display();
}
lichtwaarde = digitalRead(knoplicht);
}
//setting the day
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the day
display.println("");
display.print(" dag: ");
display.setTextSize(2);
display.println(dag);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
dag++;
if (maand == 1 || maand == 3 || maand == 5 || maand == 7 || maand == 8 || maand == 10 || maand == 12){
if (dag > 31) dag = 1;
}
if (maand == 4 || maand == 6 || maand == 9 || maand == 11){
if (dag > 30) dag = 1;
}
if (maand == 2){
if (dag > 28) dag = 1;
}
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the day
display.println("");
display.print(" dag: ");
display.setTextSize(2);
display.println(dag);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
}
lichtwaarde = digitalRead(knoplicht);
}
// year
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the year
display.println("");
display.print(" jaar");
display.setTextSize(2);
display.print(jaar);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
while (lichtwaarde == LOW){
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH){
jaar++;
if (jaar > 2100) jaar = 2013;
display.clearDisplay(); // clears the screen and buffer
display.println("v datum");
display.println(" instellen"); //setting the year
display.println("");
display.print(" jaar");
display.setTextSize(2);
display.print(jaar);
display.setTextSize(1);
display.print("+ ");
display.display();
delay(knoptijd);
}
lichtwaarde = digitalRead(knoplicht);
}
setTime(uur,minuut,seconde,dag,maand,jaar);
delay(knoptijd);
display.clearDisplay();
loop();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
if(digits < 10)
display.print('0');
display.print(digits);
}
void lichtinstellen(){
display.clearDisplay();
display.println("> Sterkte:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(lichtsterkte/10);
display.setTextSize(1);
display.println("");
display.print("+ 1----->25");
display.display();
delay(knoptijd);
lichtwaarde = LOW;
while(lichtwaarde == LOW){
display.clearDisplay();
display.println("> Sterkte:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(lichtsterkte/10);
display.setTextSize(1);
display.println("");
display.print("+ 1----->25");
display.display();
analogWrite(ledpin, lichtsterkte);
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
lichtwaarde = digitalRead(knoplicht);
if (menuwaarde == HIGH){
lichtsterkte = lichtsterkte + 10;
if (lichtsterkte == 260) lichtsterkte = 10;
analogWrite(ledpin, lichtsterkte);
}
}
loop();
}
void contrast(){
display.clearDisplay();
display.println("> Contrast:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(schermcontrast);
display.setTextSize(1);
display.println("");
display.print("+ 45%->95%");
display.display();
delay(knoptijd);
lichtwaarde = LOW;
while(lichtwaarde == LOW){
display.clearDisplay();
display.println("> Contrast:");
display.println("");
display.setTextSize(2);
display.print(" ");
display.println(schermcontrast);
display.setTextSize(1);
display.println("");
display.print("+ 45%->95%");
display.display();
delay(knoptijd);
menuwaarde = digitalRead(knopmenu);
lichtwaarde = digitalRead(knoplicht);
if (menuwaarde == HIGH){
schermcontrast = schermcontrast + 1;
if (schermcontrast == 95) schermcontrast = 45;
display.setContrast(schermcontrast);
}
}
loop();
}
void temper(){
tempteller++;
if (tempteller == 1000){
digitalWrite(temppin, HIGH);
delay(200);
tempsensor = analogRead(1)* 0.4882812;
temperatuur = tempsensor - 273.15 - 31.4; //33 is de correctie doe nodig was voor mijn sensor
digitalWrite(temppin, LOW);
tempteller = 0;
if (temperatuur > 99 || temperatuur < -99) temperatuur = 99;
}
}
void menu(){
display.setTextSize(1);
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("klok inst.");
display.setTextColor(BLACK);
display.println(" wijzerplaat");
display.println(" licht");
display.println(" contrast");
display.println("");
display.print("v terug");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) setklok();
if (menuwaarde == HIGH) menu2();
}
void menu2(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("wijzerplaat");
display.setTextColor(BLACK);
display.println(" licht");
display.println(" contrast");
display.println("");
display.println(" terug");
display.print("v klok inst.");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) wijzerplaat();
if (menuwaarde == HIGH) menu3();
}
void menu3(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("licht");
display.setTextColor(BLACK);
display.println(" contrast");
display.println("");
display.println(" terug");
display.println(" klok inst.");
display.print("v wijzerplaat");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) lichtinstellen();
if (menuwaarde == HIGH) menu4();
}
void menu4(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("contrast");
display.setTextColor(BLACK);
display.println("");
display.println(" terug");
display.println(" klok inst.");
display.println(" wijzerplaat");
display.print("v licht");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) contrast();
if (menuwaarde == HIGH) menu5();
}
void menu5(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("");
display.setTextColor(BLACK);
display.println(" terug");
display.println(" klok inst.");
display.println(" wijzerplaat");
display.println(" licht");
display.print("v contrast");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
// if (lichtwaarde == HIGH) nogOnbekend();
if (menuwaarde == HIGH) menu6();
}
void menu6(){
menuwaarde = LOW;
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("terug");
display.setTextColor(BLACK);
display.println(" klok inst.");
display.println(" wijzerplaat");
display.println(" licht");
display.println(" contrast");
display.print("v");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH){delay(knoptijd); display.clearDisplay(); loop();}
if (menuwaarde == HIGH) menu();
}
void wijzerplaat(){
lichtwaarde = LOW;
menuwaarde = LOW;
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("millidays");
display.setTextColor(BLACK);
display.println(" wijzers");
display.println(" stopwatch");
display.println(" binair");
display.println(" classic");
display.print("v big");
display.display();
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("millidays");
display.setTextColor(BLACK);
display.println(" wijzers");
display.println(" stopwatch");
display.println(" binair");
display.println(" classic");
display.print("v big");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 1;
loop();
}
if (menuwaarde == HIGH) wijzerplaat2();
}
void wijzerplaat2(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("wijzers");
display.setTextColor(BLACK);
display.println(" stopwatch");
display.println(" binair");
display.println(" classic");
display.println(" big");
display.print("v millidays");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 2;
// minoud = 61;
display.clearDisplay();
loop();
}
if (menuwaarde == HIGH) wijzerplaat3();
}
void wijzerplaat3(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("stopwatch");
display.setTextColor(BLACK);
display.println(" binair");
display.println(" classic");
display.println(" big");
display.println(" millidays");
display.print("v wijzers");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 3;
loop();
}
if (menuwaarde == HIGH) wijzerplaat4();
}
void wijzerplaat4(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("binair");
display.setTextColor(BLACK);
display.println(" classic");
display.println(" big");
display.println(" millidays");
display.println(" wijzers");
display.print("v stopwatch");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 4;
loop();
}
if (menuwaarde == HIGH) wijzerplaat5();
}
void wijzerplaat5(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("classic");
display.setTextColor(BLACK);
display.println(" big");
display.println(" millidays");
display.println(" wijzers");
display.println(" stopwatch");
display.print("v binair");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 5;
// minoud = 61;
display.clearDisplay();
loop();
}
if (menuwaarde == HIGH) wijzerplaat6();
}
void wijzerplaat6(){
menuwaarde = LOW;
delay(knoptijd);
while (lichtwaarde == LOW && menuwaarde == LOW){
display.clearDisplay();
display.print("< ");
display.setTextColor(WHITE, BLACK);
display.println("big");
display.setTextColor(BLACK);
display.println(" millidays");
display.println(" wijzers");
display.println(" stopwatch");
display.println(" binair");
display.print("v classic");
display.display();
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
}
if (lichtwaarde == HIGH) {
plaatkeuze = 6;
loop();
}
if (menuwaarde == HIGH) wijzerplaat();
}
void binair(){
display.clearDisplay();
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.print(" 1 2 4 8 ");
display.setTextColor(BLACK);
display.print(" ");
display.println(second());
int b1 = 0;
int b2 = 0;
int b3 = 0;
int b4 = 0;
int x = hour();
if (x > 12) x = x - 12;
if(x-8 >= 0){b4=1; x = x -8;}
if(x-4 >= 0){b3=1; x = x -4;}
if(x-2 >= 0){b2=1; x = x -2;}
if(x == 1){b1=1;}
display.print(" ");
display.print(b1);
display.print(" ");
display.print(b2);
display.print(" ");
display.print(b3);
display.print(" ");
display.println(b4);
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(" 1 3 ");
display.println(" 1 2 4 8 6 2 ");
display.setTextColor(BLACK);
b1 = 0;
b2 = 0;
b3 = 0;
b4 = 0;
int b5 = 0;
int b6 = 0;
x = minute();
if(x-32 >= 0){b6=1; x = x - 32;}
if(x-16 >= 0){b5=1; x = x - 16;}
if(x-8 >= 0){b4=1; x = x -8;}
if(x-4 >= 0){b3=1; x = x -4;}
if(x-2 >= 0){b2=1; x = x -2;}
if(x == 1){b1=1;}
display.print(" ");
display.print(b1);
display.print(" ");
display.print(b2);
display.print(" ");
display.print(b3);
display.print(" ");
display.print(b4);
display.print(" ");
display.print(b5);
display.print(" ");
display.print(b6);
display.display();
}
void stopwatch(){
delay(knoptijd);
long tellermini = 0;
long tellersec = 0;
long tellermin = 0;
long tellernu = 0;
while (tellerStart == 0){
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
if (menuwaarde == HIGH) menu();
if (lichtwaarde == HIGH) {
tellerStart = 1;
teller = millis();
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println("< start");
display.setTextSize(2);
display.print("00:00");
display.setTextSize(1);
display.println("00");
display.println();
display.println(" lap:");
display.print(" ");
display.println("--:--");
display.print("< menu");
display.display();
}
while (tellerStart == 1){
if (millis() - teller > 250){
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
if (lichtwaarde == HIGH) {
tellerStart = 2;
}
}
tellernu = millis() - teller;
for (int i = 0; i < 100; i++){
if (tellernu > i * 60000) tellermin = i;}
tellernu = tellernu - (tellermin * 60000);
for (int j = 0; j < 60; j++){
if (tellernu > j * 1000) tellersec = j;}
tellernu = tellernu - (tellersec * 1000);
for (int k = 0; k < 100; k++){
if (tellernu > k * 100) tellermini = k;}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println("< stop");
display.setTextSize(2);
printDigits(tellermin);
display.print(":");
printDigits(tellersec);
display.setTextSize(1);
display.print(tellermini);
display.println();
display.println();
display.println(" lap:");
display.print(" ");
display.println("--:--");
display.print("< laptijd");
display.display();
}
while (tellerStart == 2){
delay(knoptijd);
lichtwaarde = digitalRead(knoplicht);
menuwaarde = digitalRead(knopmenu);
if (lichtwaarde == HIGH) {
tellerStart = 0;
}
if (menuwaarde == HIGH) menu();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println("< reset");
display.setTextSize(2);
printDigits(tellermin);
display.print(":");
printDigits(tellersec);
display.setTextSize(1);
display.print(tellermini);
display.println();
display.println();
display.println(" lap:");
display.print(" ");
display.println("--:--");
display.print("< menu");
display.display();
}
}
void digitalClockDisplay(){ //printing time and date
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.print("Millidays");
if (temperatuur >= 0) display.print(" ");
if (temperatuur < 10 && temperatuur > 0) display.print(" ");
display.print(temperatuur);
display.write(247);
display.print("C");
display.setTextSize(2);
display.setTextColor(BLACK);
display.println(millidays);
display.setTextSize(1);
display.setTextColor(BLACK);
display.print(day());
display.print("/");
display.print(month());
display.print("/");
display.println(year());
display.setTextSize(2);
display.setTextColor(BLACK);
display.print(hour());
display.print(":");
printDigits(minute());
display.setTextSize(1);
display.print(":");
printDigits(second());
display.println();
display.display();
}
void wijzerpl(){
kleur = BLACK;
kleurwis = WHITE;
breed = 42;
display.drawCircle(breed, 24, 23, kleur);
display.drawLine(breed, 2, breed, 3, kleur);
display.drawLine(breed-22, 24, breed-21, 24, kleur);
display.drawLine(breed, 46, breed, 45, kleur);
display.drawLine(breed+22, 24, breed+21, 24, kleur);
display.display();
wijzer();
}
void classic(){
kleur = BLACK;
kleurwis = WHITE;
breed = 42;
display.setCursor(0,0);
display.println(" XII");
display.println();
display.print(" IX III");
display.println();
display.println();
display.print(" VI");
display.display();
wijzer();
}
void wijzer(){
if (millis() - tussentijd > 5000){ // wait inbetween refreshing
tussentijd = millis();
// deleting the old hands
display.fillCircle(breed, 24, 19, kleurwis);
// placing the minute hand
for (int i = 0; i < 30; i++){
if (minute() == i) display.drawLine(breed, 24, breed+breedMinWijzer[i], hoogMinWijzer[i], kleur);
if (minute() == i+30) display.drawLine(breed, 24, breed-breedMinWijzer[i], hoogMinWijzer[i+30], kleur);
}
// placing the hour hand
for (int i = 0; i < 6; i++){
if (hour() == i || hour() == i+12){
if (minute() < 10){ display.drawLine(breed, 24, breed+breedUurWijzer[i], hoogUurWijzer[i], kleur);}
else{if (minute() < 20){ display.drawLine(breed, 24, breed+breedUurWijzer[i+6], hoogUurWijzer[i+6], kleur);}
else{if (minute() < 30){ display.drawLine(breed, 24, breed+breedUurWijzer[i+12], hoogUurWijzer[i+12], kleur);}
else{if (minute() < 40){ display.drawLine(breed, 24, breed+breedUurWijzer[i+18], hoogUurWijzer[i+18], kleur);}
else{if (minute() < 50){ display.drawLine(breed, 24, breed+breedUurWijzer[i+24], hoogUurWijzer[i+24], kleur);}
else{ display.drawLine(breed, 24, breed+breedUurWijzer[i+30], hoogUurWijzer[i+30], kleur);}
}}}}}
if (hour() == i+6 || hour() == i+18){
if (minute() < 10){ display.drawLine(breed, 24, breed-breedUurWijzer[i], hoogUurWijzer[i+36], kleur);}
else{if (minute() < 20){ display.drawLine(breed, 24, breed-breedUurWijzer[i+6], hoogUurWijzer[i+42], kleur);}
else{if (minute() < 30){ display.drawLine(breed, 24, breed-breedUurWijzer[i+12], hoogUurWijzer[i+48], kleur);}
else{if (minute() < 40){ display.drawLine(breed, 24, breed-breedUurWijzer[i+18], hoogUurWijzer[i+54], kleur);}
else{if (minute() < 50){ display.drawLine(breed, 24, breed-breedUurWijzer[i+24], hoogUurWijzer[i+60], kleur);}
else{ display.drawLine(breed, 24, breed-breedUurWijzer[i+30], hoogUurWijzer[i+66], kleur);}
}}}}}
}
}
display.display();
}
void big(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.println();
display.setTextSize(3);
display.print(hour());
display.setTextSize(2);
display.print(":");
display.setTextSize(3);
printDigits(minute());
display.display();
}
Menu Structure
When you turn on the watch, you will start on the "millidays" clock face. (I'm sorry all text is in Dutch)
Millidays clock face
Top button scrolls from
Wijzerplaat (clock face)
Here you can choose the different clock faces (and you might add some)
See the pictures for the explanation off the different faces.
Licht (light)
With this function you can select the brightness of the backlight from 0 (off) till 25
Contrast
With this function you can select the contrast of the screen from 45% till 95%. (caution on my screen the text is hard to see from 45% - 50%.)
Terug (return)
By selecting this, you will go back to the last selected clock face.
Millidays clock face
- Top button tuns on/off the backlight
- Bottom button let you go to the "menu"
- Top button selects the selection (inverse color)
-
Bottom button scrolls down trough the choices
You can only scroll down. When you are at the last selection, you will start with the first again.
- klok inst. (set clock)
- wijzerplaat (clock face)
- licht (backlight)
- contrast (contrast)
- terug (return)
- Top button scrolls to the next
- Bottom button increases value
Top button scrolls from
- uur (hour)
- min. (minute)
- maand (month)
- dag (day)
- jaar (year)
- back to clock face
Wijzerplaat (clock face)
Here you can choose the different clock faces (and you might add some)
See the pictures for the explanation off the different faces.
- Top button turns on/off the back light
- Bottom button let you go to the "menu"
Licht (light)
With this function you can select the brightness of the backlight from 0 (off) till 25
- Top button selects the brigtness shown on the screen
- Bottom button turns up the brightness from 3 to 25 to 1 and then up till 25 again
Contrast
With this function you can select the contrast of the screen from 45% till 95%. (caution on my screen the text is hard to see from 45% - 50%.)
- Top button selects the contrast shown on the screen
- Bottom button turns up the contrast from 60% to 95% to 45% to 95% by 1% increments
Terug (return)
By selecting this, you will go back to the last selected clock face.
Shrinking the Project
To make this watch wearable we need to shrink it down a little.
First step in the shrinking process is to get rid of the headers. Of course we need to lose the breadboard and some of the wire.
It is a bit of a pain to desolder and remove the headers. For me it helped to first snip them into single headers with a wire clipper.
Next I soldered in the flexible wires. I only had black and red wire so I had to take care not to mix them up. I used some shrinking tube to insulate the headers on the display.
Finally add the resistors and the buttons. (I also added a thermometer-IC. That was not a big success for me. If you don't you need to remove some code)
First step in the shrinking process is to get rid of the headers. Of course we need to lose the breadboard and some of the wire.
It is a bit of a pain to desolder and remove the headers. For me it helped to first snip them into single headers with a wire clipper.
Next I soldered in the flexible wires. I only had black and red wire so I had to take care not to mix them up. I used some shrinking tube to insulate the headers on the display.
Finally add the resistors and the buttons. (I also added a thermometer-IC. That was not a big success for me. If you don't you need to remove some code)
Testing the Watch
I want to use two 3V button-cells to power this watch, so it might be a good idea to test if it will run on 6V. This is also a test to see of everything is wired up correctly.
So now the software works (kind of) and the hardware works. Now we need to find a way to get it on my arm.
So now the software works (kind of) and the hardware works. Now we need to find a way to get it on my arm.
A Watch Strap
To make it really wearable I will need to design and make an enclosure for the watch and a watch strap. The first idea was to 3d-print an enclosure and just buy normal watch-straps. There are two reasons why that didn't happen. First I don't own a 3D-printer and second, I need a place to put the batteries in the straps.
So I came up with the idea to make the enclosure and strap out of one piece of silicone.
To make this silicone strap I will need to make:
So I came up with the idea to make the enclosure and strap out of one piece of silicone.
To make this silicone strap I will need to make:
- mold
- dummy-watch
- dummy batteries
- buckle from old watch
The Mold
To make the mold
The mold is the form where the silicone will be put into and then removed from when it is dried.
For the basic form I used a scrap piece of wood and some 15 x 15 mm L-shapes aluminum. I also used some other scrap pieces of aluminum.
Making the global form
I used a two component polyester putty to refine the shape
Finishing the mold
To close al the pores and to get it really smooth I used polyester top-coat. When you work with this stuff; BE SAFE. If you don't know how to work safe with polyester than don't work with it until you do know!
The mold is the form where the silicone will be put into and then removed from when it is dried.
For the basic form I used a scrap piece of wood and some 15 x 15 mm L-shapes aluminum. I also used some other scrap pieces of aluminum.
Making the global form
- First I have drawn the global form I wanted on the piece of wood.
- By screwing pieces of 15x15 aluminum on the wood I made the basic shape.
- I used some scrap pieces to close the holes in the mold.
- Some pieces aluminum that are cut in the right size are used to make the strap part less deep than the housing part.
I used a two component polyester putty to refine the shape
- First cover the whole of the inside of the mold with the 2-component putty.
- Next smooth it out with a piece of an old credit card.
- wait until it is dry (that will not be long)
- Finally sand it al smooth with sandpaper and a Dremel.
- Repeat this steps as often as you like.
Finishing the mold
To close al the pores and to get it really smooth I used polyester top-coat. When you work with this stuff; BE SAFE. If you don't know how to work safe with polyester than don't work with it until you do know!
- make the top coat by mixing the harder and the pigment into the polyester.
- coat the inside of the mold with a brush.
- wait for it to dry.
The Dummy Watch
To make the dummy
We need to make a dummy in the shape of the electronics to put in the mold when we put in the silicone.
I made this dummy from pieces of aluminum plate.
The dummy battery
We need to make a dummy in the shape of the electronics to put in the mold when we put in the silicone.
I made this dummy from pieces of aluminum plate.
- Cut the aluminum in the exact sizes of the different parts of the electronics like the screen, the pcb of the screen, the electronics on the Arduino, the pcb of the Arduino and the buttons.
- Glue the sheets on top of each other in a way that they will get the shape of the electronics. (I used superglue)
- Make the shape a little bit more organic with polyester putty.
- Let it dry.
- Sand it smooth.
The dummy battery
- To make the dummy for the batteries, I just glued two old empty batteries on top of each other.
- Filled the gap inbetween the two batteries with putty.
- Let it dry.
- Sand it all smooth.
Casting the Strap
Prepare the mold
Before we can squeeze the silicone in the mold, we first have to prepare the mold with wax, so that we can also extract the form out of the mold when it is finished.
Fill the mold with silicone
I used a black (dark grey) silicone kit that is normally used to seal stone kitchen counters. Now the fun starts!
This is harder than I thought. It is really easy to get air trapped inside.
Before we can squeeze the silicone in the mold, we first have to prepare the mold with wax, so that we can also extract the form out of the mold when it is finished.
- Check if the dummies fit inside the mold.
- Make a wire from the battery to the watch.
- Hold the wire in place with tape/magnets.
- remove the dummies from the mold.
- Simply rub the wax into the whole inside of the mold.
- Rub hard with a soft cloth. (The hard rubbing will heat up the wax and make sure that it comes everywhere)
- Rub wax on the watch dummy and the battery dummy.
Fill the mold with silicone
I used a black (dark grey) silicone kit that is normally used to seal stone kitchen counters. Now the fun starts!
This is harder than I thought. It is really easy to get air trapped inside.
- Start with silicone in the bottom of the housing part of the mold.
- Put silicone inside the gaps in the dummy.
- Half fill the part of the strap where the battery will go.
- Put the dummy watch, wire and dummy battery in the mold.
- Push the battery dummy half in the silicone.
- Push the watch dummy all the way to the bottom. (get as little as possible of the silicone underneath the watch dummy)
- Fill the rest of the mold with silicone (try to get no air trapped in the mold)
- Remove the excess silicone with a wet credit card.
- Make sure all the parts are underneath the silicone.
- Wait for the silicone to dry (it will take at least 10 days to dry)
Demolding
Taking the watch strap out off the mold
- Wait for two weeks (I know that this is almost impossible)
- Peel the strap out of the mold. (It can help to work the flexible silicone to get it lose)
- Cut away the excess silicone on the front of the dummy watch screen.
- Remove the dummy watch out off the strap (remove the tape that is holding the wire, from the mold)
- Remove the tape from the wire.
- Cut a slit over the battery on (what will be) the back of the watch. (so you can remove the battery dummy)
- Remove the battery dummy. (be careful to leave the wires and the bottom magnet behind)
Insert the Electronics
To make the electronics removable, I added a connector to the two wires that are already in the strap. One wire will connect to the (still unconnected) Vcc wire on the Arduino. The other wire will connect to the free GND connector on the PCB of the screen (any other GROUND connection would also do)
- Connect the wires.
- Wiggle the electronics in the housing.
- Measure (or trace) what wire goes to GND and what goes to Vcc.
- Put two batteries in the space where the dummy battery used to be. (make sure that the wires are connected correctly to the batteries. I used 3 very flat magnets to connect the wires to the batteries)
The Buckle
Adding the buckle
- Remove the buckle from an old watch
- Cut an gap to make space for the lip
- Drill a hole to put the pin trough
- Montage the buckle
- Measure how big the strap needs to be
- Punch a hole (or more) in the strap
Finished
Finished watch
No not really.
There are still some things I want to change in the software:
The hardware needs lots of improvement:
So this is a nice start, who will take it to the next level?
No not really.
There are still some things I want to change in the software:
- The stopwatch doesn't work 100% yet.
- The time setting can be better.
- The thermometer doesn't work.
- New faces could be added.
- A tekst-clock should be added.
The hardware needs lots of improvement:
- The electronics should be even smaller.
- The strap opens up when you put it around your wrist.
- There are to many air bubbles in the strap.
- The strap is torn open in some areas.
So this is a nice start, who will take it to the next level?