uni watch project similar to LED pocket watch

Hi :smiley:

I am wanting to try and make a watch similar to this LED pocket watch - LED Pocket Watch | Hackaday

I've got my arduino, breadboard, LED's, resistors and my clock crystal 32.768kHz as well as wires. Is this everything I need? Do I need a capacitor? If so what one?

I need help with a few things on it such as - assembly – where does the clock crystal get placed on the board? Would it be before the LED's? and if I need a capacitor were would that go?

And?the program!! I am getting a tiny bit better at the programming but still a working progress – any ideas on the program?

Thanks

Paul

What's the 32k crystal for?
Isn't it going to be tricky fitting the Arduino into a watch case?

Hi

At the moment I am just laying out the scheme so that's why I am using arduino. From what I've gathered the crystal will help keep the time more accurate – is this true?

Paul

From what I've gathered the crystal will help keep the time more accurate – is this true?

It will make your Arduino run more slowly (32.768kHz vs. 16MHz), but unless the accuracies of the crystals are way out, why should it be more (or less) accurate?

I am new to arduino – so I just bought crystals :o should I have bought the 16MHz. Basically as I am new to arduino I am looking for bit of an outline to how I go about doing this. I could buy 16MHz crystals if this would be better as they are quit cheap!

I am new to arduino – so I just bought crystals

There should already be a crystal (either 8 or 16MHz) on the Arduino - which one did you buy?

Hi

I bought the Atmega 328 arduino duemilanove. I heard somewhere that the crystal in the arduino wasn't that good. do you have any ideas how I go about doing this? Am new to arduino so still figuring it all out.

Thanks

Paul

do you have any ideas how I go about doing this?

Yes, start with some of the examples and tutorials, and work through them until you understand them.
Maybe google "charlieplexing".

The 32.768KHz crystal is the value that you use to built an RTC (real time clock). Once you've built that (it features on other sites) you apply it's pulse (1 per second or whatever) to the Arduino from which you then generate the display.

Try googling RTC and you should get suitable circuits

jack

should have mentioned that 32768 is 2^15. so if your RTC divides the basic crystal frequency using a suitable set of binary dividers you end up with 1 pulse/second Simples

Ok ill give it go!!

thanks alot!

Hi

I have been experimenting with the starter program – 8 more LED's. I added in a total of 12 LED's using the same basic circuit layout – I added in 4 extra LED's using pins 5, 6, 7, 8. I then used the chip 74HC595 for - pin 2 – 14-Data, pin 4 – 12 – Latch and pin 3 – 11- CIK.

I am a little stuck on the program – the only lights that I can get to light up is the LED's connected straight to pins 5, 6, 7, 8. I am trying to adapt the original program see below:

Any ideas?

Thanks

Paul

/*     ---------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code             |
 *     |  CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register)   |
 *     ---------------------------------------------------------
 * 
 * We have already controlled 8 LEDs however this does it in a slightly
 * different manner. Rather than using 8 pins we will use just three
 * and an additional chip.
 *
 * For more information on this circuit http://tinyurl.com/111111/
 *
 */


//Pin Definitions
//The 74HC595 using a protocol called SPI (for more details http://www.arduino.cc/en/Tutorial/ShiftOut)
//Which has three pins
int data = 2; 
int clock = 3;
int latch = 4;

//Used for single LED manipulation
int ledState = 0;
const int ON = HIGH;
const int OFF = LOW;
                        

/*
 * setup() - this function runs once when you turn your Arduino on
 * We set the three control pins to outputs
 */
void setup()
{
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);  
  pinMode(latch, OUTPUT);  
}

/*
 * loop() - this function will start after setup finishes and then repeat
 * we set which LEDs we want on then call a routine which sends the states to the 74HC595
 */
void loop()                     // run over and over again
{
  int delayTime = 100; //the number of milliseconds to delay between LED updates
  for(int i = 0; i < 256; i++){
   updateLEDs(i);
   delay(delayTime); 
  }
}



/*
 * updateLEDs() - sends the LED states set in ledStates to the 74HC595
 * sequence
 */
void updateLEDs(int value){
  digitalWrite(latch, LOW);     //Pulls the chips latch low
  shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
  digitalWrite(latch, HIGH);   //Pulls the latch high displaying the data
}

/*
 * updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
 * sequence. Same as updateLEDs except the shifting out is done in software
 * so you can see what is happening.
 */ 
void updateLEDsLong(int value){
  digitalWrite(latch, LOW);    //Pulls the chips latch low
  for(int i = 0; i < 8; i++){  //Will repeat 8 times (once for each bit)
  int bit = value & B10000000; //We use a "bitmask" to select only the eighth 
                               //bit in our number (the one we are addressing this time through
  value = value << 1;          //we move our number up one bit value so next time bit 7 will be
                               //bit 8 and we will do our math on it
  if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
  else{digitalWrite(data, LOW);}            //if bit 8 is unset then set the data pin low
  digitalWrite(clock, HIGH);                //the next three lines pulse the clock pin
  delay(1);
  digitalWrite(clock, LOW);
  }
  digitalWrite(latch, HIGH);  //pulls the latch high shifting our data into being displayed
}


//These are used in the bitwise math that we use to change individual LEDs
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
/*
 * changeLED(int led, int state) - changes an individual LED 
 * LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
 */
 void changeLED(int led, int state){
   ledState = ledState & masks[led];  //clears ledState of the bit we are addressing
   if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
   updateLEDs(ledState);              //send the new LED state to the shift register
 }

Any ideas?

On your last post, click on "Modify", then highlight all the code in it, then click the "Code" (#) button on the editor toolbar.

Hi

i've been programming with some success it would seem. but i am little stuck at this point. below is the program line and below that is the error message.

for(int i = 0; i < 12 ; i++){ //this is a loop and will repeat eight times

error: expected initializer before 'for'

what is it trying to tell me?

Thanks

Paul

I compiled the code in reply #11 and there were no error messages.

If you changed the code since then, we will need more than the one line you posted in reply #13 to find out what the problem is.

Here it is!! This will probably be very very wrong – but it's a working process and my first proper working process - not entirely finished i dont think.

If you could have a quick look at it and tell me were its going wrong that would be great!

Thanks

Paul

//LED Pin Variables

int ledPins[] = {5,6,7,8}; //this is going to the LED's direct
                         

void setup()
{
  
  //Set each pin connected to an LED to output mode (pulling high (on) or low (off)
  for(int i = 0; i < 5 ,6, 7 , 8; i++){         //this is a loop and will repeat eight times
      pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
  }                                   //the code this replaces is below  
  
            
void loop()                     // run over and over again

  oneAfterAnotherNoLoop();  
{
void oneAfterAnotherNoLoop(){
  int delayTime = 100; //Turns the LED's on and off at 100 mileseconds 
                       
  digitalWrite(ledPins[5], HIGH);  
  delay(delayTime);      
  digitalWrite(ledPins[6], HIGH);  
  delay(delayTime);  
    digitalWrite(ledPins[7], HIGH);  
  delay(delayTime);
    digitalWrite(ledPins[8], HIGH);  
  delay(delayTime);
  
  
  //turns LEDs AFF!
   digitalWrite(ledPins[5], LOW);  
  delay(delayTime);      
  digitalWrite(ledPins[6], LOW);  
  delay(delayTime);  
    digitalWrite(ledPins[7], LOW);  
  delay(delayTime);
    digitalWrite(ledPins[8], LOW);  
  delay(delayTime);
  
}


//Pin connected to ST_CP of 74HC595
int latchPin = 4;
//Pin connected to SH_CP of 74HC595
int clockPin = 3;
////Pin connected to DS of 74HC595
int dataPin = 2;


  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() 
  // count from 0 to 255 and display the number 
  // on the LEDs
  for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
    // take the latchPin low so 
    // the LEDs don't change while you're sending in bits:
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  

    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(500);
  }
}

Well, I don't get the error you reported in reply #13, so this is definitely a moving target.

For the code in reply #15, there is an extra

void loop()

at line 15 of the code you posted.

Why did you change your code in setup() to be

  for(int i = 0; i < 5 ,6, 7 , 8; i++){         //this is a loop and will repeat eight times
      pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
  }                                   //the code this replaces is below

You might want to take an elementary refresher course at http://arduino.cc/en/Reference/HomePage

Ah! So I should delete the 'void loop ( )' ?
Ok ill delete that and let you know how it goes!

Thanks

Paul

One clocking possibility is to use the 8MHz internal RC clock for the program itself (where accuracy isn't that important), and use the 32768 crystal to clock timer2 asynchronously. Set its TOP value to 32768 and interrupt on overflow, then you can get a very accurate 1s timebase.

OK I deleted that and it didn't work.

Any ideas on how I should tackle the programming for it? I am quite new to it.

rmd6502 – that sounds like quite a good idea! How do I access the RC clock program?

Thanks

Paul

//LED Pin Variables

int ledPins[] = {5,6,7,8}; //this is going to the LED's direct
                         

void setup()
{
  
  //Set each pin connected to an LED to output mode (pulling high (on) or low (off)
  for(int i = 0; i < 5 ,6, 7 , 8; i++){         //this is a loop and will repeat eight times
      pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
  }                                   //the code this replaces is below  
  
            
       

void oneAfterAnotherNoLoop(){
  int delayTime = 100; //Turns the LED's on and off at 100 mileseconds 
                       
  digitalWrite(ledPins[5], HIGH);  
  delay(delayTime);      
  digitalWrite(ledPins[6], HIGH);  
  delay(delayTime);  
    digitalWrite(ledPins[7], HIGH);  
  delay(delayTime);
    digitalWrite(ledPins[8], HIGH);  
  delay(delayTime);
  
  
  //turns LEDs AFF!
   digitalWrite(ledPins[5], LOW);  
  delay(delayTime);      
  digitalWrite(ledPins[6], LOW);  
  delay(delayTime);  
    digitalWrite(ledPins[7], LOW);  
  delay(delayTime);
    digitalWrite(ledPins[8], LOW);  
  delay(delayTime);
  
}


//Pin connected to ST_CP of 74HC595
int latchPin = 4;
//Pin connected to SH_CP of 74HC595
int clockPin = 3;
////Pin connected to DS of 74HC595
int dataPin = 2;


  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() 
  // count from 0 to 255 and display the number 
  // on the LEDs
  for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
    // take the latchPin low so 
    // the LEDs don't change while you're sending in bits:
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  

    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(500);
  }
}