Wrist Watch
PROLOGUE
A while back I bought a pair of QDSP-6064 LED bubble displays. I didn’t know much of what I wanted to do with them, but I did know I wanted to make a wrist watch. The project was shevled until I learned EagleCAD, but here are the notes, code and CAM files for you to be able to make one yourself.
Core Components Needed
1. ATMEGA-328P and related components
2. A QDSP-6064 Bubble Display
Let’s get it on
Solder it up, and flash it!
#include <TimeLib.h>
#include <Time.h>
#include "SevSeg.h"
//date --date="-5 hours" +T%s\n > /dev/ttyACM0
//Create an instance of the object.
SevSeg myDisplay ;
//Create global variables
unsigned long timer ;
unsigned long blinker ;
unsigned long displaysleep ;
boolean blinkdisplay = true ;
boolean displaypower = true ;
boolean buttonActive = false ;
boolean longPressActive = false ;
boolean confighours = true ;
long buttonTimer = 0 ;
long longPressTime = 1000 ;
time_t t = now ();
int button = A5 ;
boolean timeset = false ;
#define TIME_HEADER "T"
#define TIME_REQUEST 7
void setup ()
{
pinMode ( button , INPUT );
int displayType = COMMON_CATHODE ; //Your display is either common cathode or common anode
Serial . begin ( 9600 );
//This pinout is for a bubble dispaly
//Declare what pins are connected to the GND pins (cathodes)
int digit1 = 8 ; //Pin 1
int digit2 = 5 ; //Pin 10
int digit3 = 11 ; //Pin 4
int digit4 = 13 ; //Pin 6
//Declare what pins are connected to the segments (anodes)
int segA = 7 ; //Pin 12
int segB = 6 ; //Pin 11
int segC = 10 ; //Pin 3
int segD = 3 ; //Pin 8
int segE = 9 ; //Pin 2
int segF = 4 ; //Pin 9
int segG = 2 ; //Pin 7
int segDP = 12 ; //Pin 5
int numberOfDigits = 4 ;
myDisplay . Begin ( displayType , numberOfDigits , digit1 , digit2 , digit3 , digit4 , segA , segB , segC , segD , segE , segF , segG , segDP );
myDisplay . SetBrightness ( 100 );
timer = millis ();
blinker = millis ();
displaysleep = millis () + 10000 ;
setSyncProvider ( requestSync );
Serial . println ( "Waiting for sync message" );
}
void loop ()
{
if ((( signed long )( millis () - timer )) > 0 ) {
timer = millis () + 1000 ;
Serial . println ( displaysleep );
}
char tempString [ 10 ]; //Used for sprintf
sprintf ( tempString , "%02d%02d" , hour ( now ()), minute ( now ()));
if ( blinkdisplay == true ) {
displaysleep = millis () + 10000 ;
if ((( signed long )( millis () - blinker )) > 0 ) {
if ( displaypower == true ) {
displaypower = false ;
} else {
displaypower = true ;
}
blinker = millis () + 1000 ;
}
} else {
displaypower = true ;
}
if ((((( signed long )( millis () - displaysleep )) < 0 ) && displaypower == true )) {
//Serial.println("display put to sleep");
//displaypower = false;
//}
//if (displaypower == true) {
myDisplay . DisplayString ( tempString , 0 );
}
if ( digitalRead ( button ) == HIGH ) {
displaysleep = millis () + 10000 ;
if ( buttonActive == false ) {
buttonActive = true ;
buttonTimer = millis ();
}
if (( millis () - buttonTimer > longPressTime ) && ( longPressActive == false )) {
longPressActive = true ;
if ( timeset == false ) {
Serial . println ( "Configuring time" );
blinkdisplay = true ;
confighours = ! confighours ;
} else {
setTime ( now ());
blinkdisplay = false ;
Serial . println ( "Done configuring time" );
}
timeset = ! timeset ;
}
} else {
//displaysleep = millis()+10000;
if ( buttonActive == true ) {
if ( longPressActive == true ) {
longPressActive = false ;
} else {
if ( timeset == true ) {
if ( confighours == true ) {
t = now () + 3600 ;
} else {
t = now () + 60 ;
}
setTime ( t );
blinkdisplay = false ;
}
}
buttonActive = false ;
}
}
if ( Serial . available ()) {
processSyncMessage ();
}
}
void processSyncMessage () {
unsigned long pctime ;
const unsigned long DEFAULT_TIME = 0 ; //1357041600; // Jan 1 2013
if ( Serial . find ( TIME_HEADER )) {
pctime = Serial . parseInt ();
if ( pctime >= DEFAULT_TIME ) { // check the integer is a valid time (greater than Jan 1 2013)
setTime ( pctime ); // Sync Arduino clock to the time received on the serial port
timeset = false ;
blinkdisplay = false ;
}
}
}
time_t requestSync ()
{
Serial . write ( TIME_REQUEST );
return 0 ; // the time will be sent later in response to serial mesg
}