DS1307 Color Clock Wristwatch

Views: 3592 Difficulty: 4 Status: Development
Wristwatch_lucid

A wearable real-time clock with vibrant color display.

Using the enchanting TFT LCD Screen from adafruit and the DS1307 chip for keeping the time we demonstrate a wearable wristwatch with full spectrum 16-bit color. Displays the time and date in analog, digital and animated formats. Using our color library we color code the time so that each minute is a journey through the rainbow! The watch contains a Piezo buzzer so it can be used as an alarm or as a stop watch. The on-board potentiometer lets you change the time should you find yourself in a new time zone, for example. There is a great tutorial at adafruit on how to use the DS1307 chip to keep track of time. Our circuit is based on that one but use surface mount components and hooks up directly to the SDA and SCL pins on the SMD Atmega328 IC. If you want to turn this watch into a bonafide alarm clock, check out our alarming tutorial!

Little Watch

Screen_shot_2013-03-01_at_7.31.04_pm
Won't melt in the palm off your hand...

Triple Time Video

Watch the rainbow clock in triple speed!

Arduino Code

This code will draw the current time according to the DS1307 chip. At the the top and bottom of the LCD screen the code displays the time and date digitally, and in the center shows a rainbow colored analog clock. This code relies on several libraries: RTCLib adafruit fork, the ST7735 LCD Screen library (thanks again adafruit!). We also use our color library and the SPI and Wire libs.
/* LucidTronix color compass 
 * Rainbow colored rtc clock
 * For instructions, details and schematic, See:
 * http://www.lucidtronix.com/tutorials/29
 * Uses the RTClib.h library from adafruit
 */
#include <ST7735.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <color.h>


#define cs 10   // for MEGAs you probably want this to be pin 53
#define dc 9
#define rst 8  // you can also connect this to the Arduino reset

ST7735 tft = ST7735(cs, dc, rst);

// Reference the I2C LibraUry
#include <Wire.h>


int btnPin0 = 0;
int btnPin1 = 1;
int btnPin2 = 2;

int mode = 0;
int num_modes = 4;
int cur_sec = 0;
int cur_min = 0;
int millisecond_six = 0;
unsigned int last_sec = 0;

unsigned int last_press = 0;

RTC_DS1307 RTC;

DateTime cur_time, alarm_time;

char* stringy = "nothinghere";
void setup(){
  
  Serial.begin(57600);

  pinMode(btnPin2,INPUT);
  pinMode(btnPin1,INPUT);
  pinMode(btnPin0,INPUT);

  tft.initR();               // initialize a ST7735R chip
  tft.writecommand(ST7735_DISPON); 
 
  delay(1000);
  tft.fillScreen(BLACK);
  tft.drawString(4, 4, "Starting up...", CYAN,1);
  Wire.begin(); // Start the I2C interface.
  tft.drawString(4, 64,"Hello?!", GREEN);
  RTC.begin();

  if (! RTC.isrunning()) {
    tft.drawString(14, 94,"RTC is NOT running!",RED);
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  delay(500);
  tft.fillScreen(WHITE);

}
void loop(){
  cur_time = RTC.now();
  display_time_digital(2, 4,1);
  display_date(2,135,1);
  color_clock(64,80);
  check_buttons();
}

void display_time_digital(int ax, int ay, int text_size){
  
  print_integer(ax,ay, cur_time.hour(), text_size);
  tft.drawString(ax+(text_size*10), ay,":",MAGENTA, text_size); 
  print_integer(ax+(text_size*15),ay, cur_time.minute(), text_size);
  tft.drawString(ax+(text_size*25), ay,":",RED,text_size); 
  print_integer(ax+(text_size*30),ay, cur_time.second(), text_size);  
  if (cur_sec != cur_time.second() ){
   last_sec = millis();
   cur_sec = cur_time.second();
   tft.fillRect(ax+(text_size*30), ay-2, text_size*12, text_size*10,WHITE);  
  }
}
void display_date(int ax, int ay,int text_size){
  print_integer(ax,ay, cur_time.month(), text_size);
  tft.drawString(ax+(text_size*10), ay,"/",GREEN,text_size); 
  print_integer(ax+(text_size*15),ay, cur_time.day(), text_size);
  tft.drawString(ax+(text_size*25), ay,"/",YELLOW,text_size); 
  print_integer(ax+(text_size*30),ay, cur_time.year(), text_size);
}
void color_clock(int ax, int ay){
  int hour_angle = cur_time.hour()*30;
  int minute_angle = cur_time.minute()*6;
  int second_angle = cur_time.second()*6;
  if (cur_min != cur_time.minute() ){
    cur_min = cur_time.minute();
    tft.fillScreen(WHITE);
    tft.drawString(58, 8,"12",BLACK,2); 

  }
  if (cur_sec != cur_time.second() ){
   last_sec = millis();
   cur_sec = cur_time.second();
  }
  millisecond_six = constrain(((millis()-last_sec) / 167),0,6);
  int second_angle_hi_res = (cur_sec*6) + millisecond_six;
  draw_orbiter(ax,ay,hour_angle, 20,3);
  draw_ray(ax,ay,hour_angle, 20);
  draw_orbiter(ax,ay,minute_angle, 25,2); 
  draw_ray(ax,ay,minute_angle, 25);
  draw_orbiter(ax,ay,second_angle_hi_res, 48,5); 
}
void draw_ray(int ax, int ay, int angle, int radius ){
  float ray_x = sin(((float)angle*PI)/180.0f)*(float)radius;
  float ray_y = -cos(((float)angle*PI)/180.0f)*(float)radius;
  int c = get_color_from_angle(angle);
  tft.drawLine(ax,ay,ax+ray_x, ay+ray_y, c);
}
void draw_orbiter(int ax, int ay, int angle, int radius, int a_size){
  float ray_x = sin(((float)angle*PI)/180.0f)*(float)radius;
  float ray_y = -cos(((float)angle*PI)/180.0f)*(float)radius;
  int c = get_color_from_angle(angle);
  tft.fillCircle(ax+ray_x, ay+ray_y, a_size, c);
}
int get_color_from_angle(int angle){
  Color cur_color=Color(0,0,0);
  cur_color.convert_hcl_to_rgb((float)angle/360,0.95,0.7);
  return cur_color.get_color_16bit(); 
}
void print_integer(int ax, int ay, int to_print, int text_size){
  char aBuf[6];
  String output = String(to_print);
  output.toCharArray(aBuf,6);
  tft.drawString(ax, ay,aBuf,BLUE,text_size); 
}
void check_buttons(){
 if ( digitalRead(btnPin0) == HIGH)   tft.fillScreen(WHITE);
 //else if ( digitalRead(btnPin1) == HIGH)   tft.fillScreen(BLACK);
 else if ( digitalRead(btnPin2) == HIGH)   tft.fillScreen(RED);
}

Parts

Title Description # Cost Link Picture
PCB Wearable Wayfinder PCB holds a DS1307 rtc clock and TFT LCD Screen 1 $9.95 Link Pcb_front_naked
TFT LCD Screen 1.8 inch 160 x 128 pixels LCD screen. ST7735R driver. JDT-1800. 1 $9.95 Link Id618_lrg
Clock IC RTC DS1307 Serial 512K 8-SOIC I²C, 2-Wire Serial Leap Year, NVSRAM, Square Wave Output Value: 4.5 V ~ 5.5 V 1 $3.53 Link 8-soic_751
ATMEGA328P-AU Integrated Circuits (ICs) MCU AVR 32K FLASH 32TQFP Value: 1.8 V ~ 5.5 V 20MHz 1 $3.05 Link Screen_shot_2012-12-28_at_7.31.33_pm
Voltage Regulator 3v3 SMD IC REG LDO 3.3V .15A SOT23 Up to 6V input output 3.3V 150mA (Max) Value: 3.3V 1 $0.46 Link Sot-23-3_pkg
CD4050 IC BUFF/CONVERTER HEX 16SOICN 8mA, 48mA Value: 3 V ~ 18 V 1 $0.45 Link 16-soic_(7.5mmwidth)
Button Tactile switch SMD SPST 0.05A 12V Value: SPST 2 $0.2 Link Fsm4jsma
Permalink: http://lucidtronix.com/tutorials/29
Viewed: 10:51PM, Jun 19
Viewed: 10:50PM, Jun 19
Viewed: 10:45PM, Jun 19
Viewed: 10:43PM, Jun 19
Viewed: 10:41PM, Jun 19
Viewed: 10:29PM, Jun 19
Viewed: 10:26PM, Jun 19
Viewed: 10:11PM, Jun 19
Viewed: 10:02PM, Jun 19
Viewed: 9:34PM, Jun 19
Viewed: 9:23PM, Jun 19
Viewed: 8:43PM, Jun 19
Viewed: 8:40PM, Jun 19
Viewed: 8:28PM, Jun 19
Viewed: 8:17PM, Jun 19
Viewed: 8:08PM, Jun 19
Go to page: 1 2 3