I have finally got the wiring sorted out so it is now working correctly.
My Minor Project is a Binary-Coded Decimal (BCD) Light Emmiting Diode (LED) Chronological Gauging Mechanisum(CGM).
The BCDLEDCGM is laid out like this:
Hours
*
8
*
4
* *
2 2
* *
1 1
Minutes
*
8
* *
4 4
* *
2 2
* *
1 1
Seconds
*
8
* *
4 4
* *
2 2
* *
1 1
Here are some pictures of it working:
This picture shows the clock at 12:07am in 24hr time.
This picture shows the clock at 2:22am in 24hr time.
This is the sketch that the Arduino is running:
//Pin connected to DS of 74HC595
const int hourDataPin = 5;
const int minDataPin = 8;
const int secDataPin = 11;
//Pin connected to SH_CP of 74HC595
const int hourClockPin = 6;
const int minClockPin = 9;
const int secClockPin = 12;
//Pin connected to ST_CP of 74HC595
const int hourLatchPin = 7;
const int minLatchPin = 10;
const int secLatchPin = 13;
// macros from DateTime.h
/* Useful Constants */
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24L)
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)
void setup()
{
pinMode(hourLatchPin, OUTPUT);
pinMode(minLatchPin, OUTPUT);
pinMode(secLatchPin, OUTPUT);
pinMode(hourClockPin, OUTPUT);
pinMode(minClockPin, OUTPUT);
pinMode(secClockPin, OUTPUT);
pinMode(hourDataPin, OUTPUT);
pinMode(minDataPin, OUTPUT);
pinMode(secDataPin, OUTPUT);
void loop()
{
unsigned long time = millis() / 1000;
int tenHours = ((numberOfHours(time) - (numberOfHours(time) % 10))/ 10);
int oneHours = numberOfHours(time) % 10 ;
int tenMinutes = ((numberOfMinutes(time) - (numberOfMinutes(time) % 10))/ 10);
int oneMinutes = numberOfMinutes(time) % 10 ;
int tenSeconds = ((numberOfSeconds(time) - (numberOfSeconds(time) % 10))/ 10);
int oneSeconds = numberOfSeconds(time) % 10 ;
int shiftHours = ((tenHours<<4) + oneHours);
int shiftMinutes = ((tenMinutes<<4) + oneMinutes);
int shiftSeconds = ((tenSeconds<<4) + oneSeconds);
digitalWrite(hourLatchPin, LOW);
digitalWrite(minLatchPin, LOW);
digitalWrite(secLatchPin, LOW);
// shift out the bits:
shiftOut(hourDataPin, hourClockPin, LSBFIRST,shiftHours);
shiftOut(minDataPin, minClockPin, LSBFIRST,shiftMinutes);
shiftOut(secDataPin, secClockPin, LSBFIRST,shiftSeconds);
//take the latch pin high so the LEDs will light up:
digitalWrite(hourLatchPin, HIGH);
digitalWrite(minLatchPin, HIGH);
digitalWrite(secLatchPin, HIGH);
delay(1000);
}
Showing posts with label Minor Project. Show all posts
Showing posts with label Minor Project. Show all posts
Friday, May 21, 2010
Friday, April 30, 2010
Minor Project - LED Binary Clock Intentions
For my Minor Project, I intend to build the rest of the LED Binary Clock. This will mean using three shift registers to control 20 LEDs seperately. Also, if i can, i will try to program it so that i will be able to set the time on the clock using three push buttons.
Saturday, April 17, 2010
LED Binary 60 Seconds 2.0 - refined code
I have done some research and have found a much simpler yet more complex code to out put exactly the same pattern with seven LEDs.
Here is the new code:
const int nbr10SecBits = 3; //10 seconds' number of pins.
const int first10SecPin = 2; //First 10 seconds pin.
const int nbr1SecBits = 4; //1 seconds' number of pins.
const int first1SecPin = 8; //First 1 seconds pin.
// macros from DateTime.h
/* Useful Constants */
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24L)
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)
void setup()
{
Serial.begin(9600);
for(int i=0; i < nbr10SecBits; i++)
pinMode(i+first10SecPin, OUTPUT);
for(int i=0; i < nbr1SecBits; i++)
pinMode(i+first1SecPin, OUTPUT);
}
void loop()
{
unsigned long time = millis() / 1000;
int tenSeconds = ((numberOfSeconds(time) - (numberOfSeconds(time) % 10))/ 10);
int oneSeconds = numberOfSeconds(time) % 10 ;
showBinary(tenSeconds,nbr10SecBits,first10SecPin);
showBinary(oneSeconds,nbr1SecBits,first1SecPin);
Serial.print(numberOfSeconds(time));
Serial.print(tenSeconds);
Serial.print(oneSeconds);
Serial.println();
delay(1000);
}
// this function sets the pins starting from firstPin to the binary value of the given number
void showBinary( int number, int nbrPins, int firstPin)
{
for(int bit=0; bit < nbrPins; bit++)
{
boolean isBitSet = bitRead(number, bit); // isBitSet will be true if given bit is set in this channel
digitalWrite(bit + firstPin, isBitSet);
}
}
Here is the new code:
const int nbr10SecBits = 3; //10 seconds' number of pins.
const int first10SecPin = 2; //First 10 seconds pin.
const int nbr1SecBits = 4; //1 seconds' number of pins.
const int first1SecPin = 8; //First 1 seconds pin.
// macros from DateTime.h
/* Useful Constants */
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24L)
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)
void setup()
{
Serial.begin(9600);
for(int i=0; i < nbr10SecBits; i++)
pinMode(i+first10SecPin, OUTPUT);
for(int i=0; i < nbr1SecBits; i++)
pinMode(i+first1SecPin, OUTPUT);
}
void loop()
{
unsigned long time = millis() / 1000;
int tenSeconds = ((numberOfSeconds(time) - (numberOfSeconds(time) % 10))/ 10);
int oneSeconds = numberOfSeconds(time) % 10 ;
showBinary(tenSeconds,nbr10SecBits,first10SecPin);
showBinary(oneSeconds,nbr1SecBits,first1SecPin);
Serial.print(numberOfSeconds(time));
Serial.print(tenSeconds);
Serial.print(oneSeconds);
Serial.println();
delay(1000);
}
// this function sets the pins starting from firstPin to the binary value of the given number
void showBinary( int number, int nbrPins, int firstPin)
{
for(int bit=0; bit < nbrPins; bit++)
{
boolean isBitSet = bitRead(number, bit); // isBitSet will be true if given bit is set in this channel
digitalWrite(bit + firstPin, isBitSet);
}
}
Subscribe to:
Posts (Atom)

