Homemade digital clock

Yesterday I made a clock using an arduino kit that I purchased for my “Creative Electronics for Beginners” class. It only counts from 0 to 9 and then repeats, but I love the satisfaction I get when I see it working.

I made a clock!
I made a clock! on Flickr.

I did happen to bump one of the LEDs just before I started taping, and discovered afterward that I had shorted one of the lights from the current. It just needed to be nudged slightly, but in the video it appears to be burnt out.

The code after the jump.

/* ---------------------------------------------------------
* | Arduino Experimentation Kit Clock Code |
* | Making a basic counter from 0 to 9 |
* ---------------------------------------------------------
*
*
* Written by Jeff Milner http://jeffmilner.com
*
*/

//LED Pin Variables
int ledPins[] = {2,3,4,5,6,7,8}; //An array to hold the pin each LED is connected to

void setup()
{

//Set each pin connected to an LED to output mode (pulling high (on) or low (off)
for(int i = 0; i < 7; i++){ //this is a loop and will repeat eight times pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output } } void loop(){ // run over and over again zero(); one(); //this will run the function to turn on the number 1 two(); three(); four(); five(); six(); seven(); eight(); nine(); } /* * zero() - Will light the outside LEDs creating a zero, pause for 1 second and * then turn off. */ void zero(){ //turns off all LEDs to start for(int i=0; i <= 8; i++) { digitalWrite(ledPins[i], LOW); } int delayTime = 1000; digitalWrite(ledPins[0], HIGH); digitalWrite(ledPins[1],HIGH); digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[4],HIGH); digitalWrite(ledPins[5],HIGH); digitalWrite(ledPins[6],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void one(){ int delayTime = 1000; digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[4],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void two(){ int delayTime = 1000; digitalWrite(ledPins[0],HIGH); digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[3],HIGH); digitalWrite(ledPins[5],HIGH); digitalWrite(ledPins[6],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void three(){ int delayTime = 1000; digitalWrite(ledPins[0],HIGH); digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[3],HIGH); digitalWrite(ledPins[4],HIGH); digitalWrite(ledPins[6],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void four(){ int delayTime = 1000; digitalWrite(ledPins[1],HIGH); digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[3],HIGH); digitalWrite(ledPins[4],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void five(){ int delayTime = 1000; digitalWrite(ledPins[0],HIGH); digitalWrite(ledPins[1],HIGH); digitalWrite(ledPins[3],HIGH); digitalWrite(ledPins[4],HIGH); digitalWrite(ledPins[6],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void six(){ int delayTime = 1000; digitalWrite(ledPins[0],HIGH); digitalWrite(ledPins[1],HIGH); digitalWrite(ledPins[3],HIGH); digitalWrite(ledPins[4],HIGH); digitalWrite(ledPins[5],HIGH); digitalWrite(ledPins[6],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void seven(){ int delayTime = 1000; digitalWrite(ledPins[0],HIGH); digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[4],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void eight(){ int delayTime = 1000; digitalWrite(ledPins[0],HIGH); digitalWrite(ledPins[1],HIGH); digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[3],HIGH); digitalWrite(ledPins[4],HIGH); digitalWrite(ledPins[5],HIGH); digitalWrite(ledPins[6],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } } void nine(){ int delayTime = 1000; digitalWrite(ledPins[0],HIGH); digitalWrite(ledPins[1],HIGH); digitalWrite(ledPins[2],HIGH); digitalWrite(ledPins[3],HIGH); digitalWrite(ledPins[4],HIGH); digitalWrite(ledPins[6],HIGH); delay(delayTime); //wait before turning off for(int i=0; i <= 6; i++) { digitalWrite(ledPins[i], LOW); } }

Leave a Reply

Your email address will not be published. Required fields are marked *