Monday 21 November 2011

More on the Chess Clocks

Right....here is where we are!!!

We have got some Seven Segment LED Displays (They are cool, green and common Cathode!)  We have connected them to four 74HC595 latching shift registers and driven these shift registers with three Control lines and the ground connection from an arduino.  With this circuit we made a 1 hour up counter.

Here is the updated Schematic Diagram.  I intend to route this to a PCB soon so that I can make a more permanent version of the circuit and get rid of the horrible mess of wires on the breadboard.  We will be making two of them for each clock.  But each clock will be driven from one arduino.


I have removed the arduino as we are going to lay out a PCB and I will use wires to connect the PCB to the arduino.  I have also added some current limiting resistors to the outputs of the shift registers.  I don't want any issues with over current to the displays.  I should really have added these to the breadboard but I was short on space.  If you are driving the circuit from a current limited supply there would not be an issue.  It is better to be safe than sorry though and that is why I have added the resistors.

I am working on getting this laid out on a single or double sided PCB which I will probably etch and drill myself at a later date.

I also wrote a new arduino sketch to make the displays count down.  The program does exactly the same thing as the previous sketch except that it counts down for an hour instead of up!.


/*
 Langster's Code for driving 4x seven segment displays via 4x Shift Registers
 This sketch will make a One Hour Down Counter!  After an hour has passed the count 
 will reset


 Repeat these steps four times for the different shift registers

 Connect Pin 3 and pin 10 on the seven segment display to 0V
 Connect all the other pins to the Shift Register digital ouputs 
 as listed below:

 pin 1 of 74HC595 to Seven Segment LED pin 6  
 pin 2 of 74HC595 to Seven Segment LED pin 4
 pin 3 of 74HC595 to Seven Segment LED pin 2
 pin 4 of 74HC595 to Seven Segment LED pin 1
 pin 5 of 74HC595 to Seven Segment LED pin 9
 pin 6 of 74HC595 to Seven Segment LED pin 8
 pin 7 of 74HC595 to Seven Segment LED pin 5
 pin 8 of 74HC595 to 0V

 pin 9 of 74HC595 is of shift register One is connected to pin 14 of 
 shift register Two...etc

 pin 10 of 74HC595 to +5V
 pin 11 of 74HC595 to Arduino pin 12  
 pin 12 of 74HC595 to Arduino pin 13
 pin 13 of 74HC595 is connected to 0V - 0V is better!
 pin 14 of 74HC595 to Arduino pin 11 for first shift register
 pin 15 of 74HC595 to Seven Segment LED pin 7
 pin 16 of 74HC595 to +5V


*/


int minutesTens = 5; // count the minutes tens


int minutesUnits = 9; // count the minutes units 


int secondsTens = 5; // count the seconds tens


int secondsUnits = 9; // count the seconds units


// Pin connected to ST_CP (pin 12) of 74HC595
int latchPin = 13;


// Pin connected to SH_CP (pin 11 of 74HC595
int clockPin = 12;


// Pin connected to DS (pin 14) of 74HC595
int dataPin = 11;


// Initialise a two Dimensional integer array with 
// the values for 0 - 9 on the Seven Segment LED Display
// and 0-9 with the decimal point!


int seven_seg_digits[2][10]= {
                             { 189,132,47,143,150,155,187,140,191,158   },
                             { 253,196,111,207,214,219,251,204,255,222  }
                             };


/*
   
  without decimal point 
  { 1,0,1,1,1,1,0,1 },  // = 189 in decimal
  { 1,0,0,0,0,1,0,0 },  // = 132 in decimal
  { 0,0,1,0,1,1,1,1 },  // = 47 in decimal 
  { 1,0,0,0,1,1,1,1 },  // = 143 in decimal
  { 1,0,0,1,0,1,1,0 },  // = 150 in decimal
  { 1,0,0,1,1,0,1,1 },  // = 155 in decimal
  { 1,0,1,1,1,0,1,1 },  // = 187 in decimal
  { 1,0,0,0,1,1,0,0 },  // = 140 in decimal
  { 1,0,1,1,1,1,1,1 },  // = 191 in decimal
  { 1,0,0,1,1,1,1,0 },  // = 158 in decimal
  
  with decimal point
  { 1,1,1,1,1,1,0,1 },  // = 253 in decimal
  { 1,1,0,0,0,1,0,0 },  // = 196 in decimal
  { 0,1,1,0,1,1,1,1 },  // = 111 in decimal 
  { 1,1,0,0,1,1,1,1 },  // = 207 in decimal
  { 1,1,0,1,0,1,1,0 },  // = 214 in decimal
  { 1,1,0,1,1,0,1,1 },  // = 219 in decimal
  { 1,1,1,1,1,0,1,1 },  // = 251 in decimal
  { 1,1,0,0,1,1,0,0 },  // = 204 in decimal
  { 1,1,1,1,1,1,1,1 },  // = 255 in decimal
  { 1,1,0,1,1,1,1,0 },  // = 158 in decimal




//  Just for further reference here are the 
//  separate segment connections


  pin 2 = C
  pin 3 = DOT
  pin 4 = E
  pin 5 = F
  pin 6 = A
  pin 7 = B
  pin 8 = G
  pin 9 = D


*/


void setup() {
  // set the arduino pins to output so you 
  // can control the shift register(s)
  
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  
  //Turn on the serial Monitor - useful for debugging!
  Serial.begin(9600);
  
  //take the latch pin of the shift register(s) low
  digitalWrite(latchPin, LOW);
  
  shiftOut(dataPin, clockPin, LSBFIRST, 0); // clears the 4th or secondUnits display
  shiftOut(dataPin, clockPin, LSBFIRST, 0); // clears the 3rd or secondTens display
  shiftOut(dataPin, clockPin, LSBFIRST, 0); // clears the 2nd or minutesUnits display
  shiftOut(dataPin, clockPin, LSBFIRST, 0); // clears the 1st or minutesTens display
  
  //take the latch pin of the shift register(s) high
  digitalWrite(latchPin, HIGH);
}


void timerCountDown(){
  
        for (secondsUnits = 9; secondsUnits >= 0; secondsUnits--){
            
            // take the latch pin of the shift register low
            digitalWrite(latchPin, LOW);   
            
            // Update the displays with the respective values 
            shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[0][secondsUnits]);    
            shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[0][secondsTens]); 
            shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[1][minutesUnits]); 
            shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[0][minutesTens]); 
            
            // take the latch pin high so the LEDs will light up:      
            digitalWrite(latchPin, HIGH);
            
            // pause for a second before next value:
            delay(100);
                      
            // for debugging send the count to the serial monitor
            
            Serial.print("Timer Count = ");
            Serial.print(minutesTens);
            Serial.print(minutesUnits);
            Serial.print(":");
            Serial.print(secondsTens);
            Serial.println(secondsUnits);       
            
            // check if the Seconds count is at 10 
            // if it is decrement the Seconds Tens count 
            // and reset the Minutes unit count to zero
  
            if (minutesTens == 6 && minutesUnits == 0 && secondsTens == 0 && secondsUnits == 0){
                Serial.println("you are here!");
                minutesTens = 5;
                minutesUnits = 9;
                secondsTens = 6;
                secondsUnits = 0;
                }    
            
            if (minutesTens == 0 && minutesUnits == 0 && secondsTens == 0 && secondsUnits == 0){
                minutesTens = 5;
                minutesUnits = 9;
                secondsTens = 6;
                secondsUnits = 9;
                }    
        
            if (minutesUnits == 0 && secondsTens == 0 && secondsUnits == 0){
                minutesTens--;
                minutesUnits = 9;
                }
                                  
            if (secondsTens == 0 && secondsUnits == 0){
               minutesUnits--;
               secondsTens = 6;
               }                
              
            if (secondsUnits == 0){
               secondsTens--;
               secondsUnits = 0;
               }                              
       }
}
   


void loop() {   
  
  // call the function timerCountDown!
  timerCountDown();


}  


I will post a video of the circuit working some other time.  Enjoy people!  




No comments :

Post a Comment