Go Down

Topic: Arduino Clock (Read 93 times) previous topic - next topic

mrosauri

Here is the code I wrote for a basic arduino 7-segment clock display.

unsigned char tick = 0;         
unsigned char tenhours = 1;        //Set Initial Time
unsigned char hours = 5;
unsigned char tenminutes = 0;
unsigned char minutes = 6;
unsigned char tenseconds =5;
unsigned char seconds = 8;
unsigned char alarmtenhours = 1;   //Set Alarm
unsigned char alarmhours = 5;
unsigned char alarmtenminutes = 0;
unsigned char alarmminutes = 7;
unsigned char alarmtenseconds = 0;
unsigned char alarmseconds = 0;
   
void setup(){                      //Initialize all pins as outputs
  pinMode(22,OUTPUT);              //LED 1 segment a
  pinMode(23,OUTPUT);              //LED 1 segment b
  pinMode(24,OUTPUT);              //LED 1 segment c
  pinMode(25,OUTPUT);              //LED 1 segment d
  pinMode(26,OUTPUT);              //LED 1 segment e
  pinMode(27,OUTPUT);              //LED 1 segment f
  pinMode(28,OUTPUT);              //LED 1 segment g
  pinMode(29,OUTPUT);              //LED 2 segment a
  pinMode(30,OUTPUT);              //LED 2 segment b
  pinMode(31,OUTPUT);              //LED 2 segment c
  pinMode(32,OUTPUT);              //LED 2 segment d
  pinMode(33,OUTPUT);              //LED 2 segment e
  pinMode(34,OUTPUT);              //LED 2 segment f
  pinMode(35,OUTPUT);              //LED 2 segment g
  pinMode(36,OUTPUT);              //LED 3 segment a
  pinMode(37,OUTPUT);              //LED 3 segment b
  pinMode(38,OUTPUT);              //LED 3 segment c
  pinMode(39,OUTPUT);              //LED 3 segment d
  pinMode(40,OUTPUT);              //LED 3 segment e
  pinMode(41,OUTPUT);              //LED 3 segment f
  pinMode(42,OUTPUT);              //LED 3 segment g
  pinMode(43,OUTPUT);              //LED 4 segment a
  pinMode(44,OUTPUT);              //LED 4 segment b
  pinMode(45,OUTPUT);              //LED 4 segment c
  pinMode(46,OUTPUT);              //LED 4 segment d
  pinMode(47,OUTPUT);              //LED 4 segment e
  pinMode(48,OUTPUT);              //LED 4 segment f
  pinMode(49,OUTPUT);              //LED 4 segment g
  pinMode(8,OUTPUT);              //Alarm
  digitalWrite(8, HIGH);           //Sets alarm off initially
}




void display_time () {                //Display Time Function

//TenHours (First LED)
if (tenhours==0){
  digitalWrite(29, LOW);
  digitalWrite(30, LOW);
  digitalWrite(31, LOW);
  digitalWrite(32, LOW);
  digitalWrite(33, LOW);
  digitalWrite(34, LOW);
  digitalWrite(35, HIGH);}
 
if (tenhours==1){
  digitalWrite(29, HIGH);
  digitalWrite(30, LOW);
  digitalWrite(31, LOW);
  digitalWrite(32, HIGH);
  digitalWrite(33, HIGH);
  digitalWrite(34, HIGH);
  digitalWrite(35, HIGH);}
 
if (tenhours==2){
  digitalWrite(29, LOW);
  digitalWrite(30, LOW);
  digitalWrite(31, HIGH);
  digitalWrite(32, LOW);
  digitalWrite(33, LOW);
  digitalWrite(34, HIGH);
  digitalWrite(35, LOW);}
 
if (tenhours==3){
  digitalWrite(29, LOW);
  digitalWrite(30, LOW);
  digitalWrite(31, LOW);
  digitalWrite(32, LOW);
  digitalWrite(33, HIGH);
  digitalWrite(34, HIGH);
  digitalWrite(35, LOW);}
 
if (tenhours==4){
  digitalWrite(29, HIGH);
  digitalWrite(30, LOW);
  digitalWrite(31, LOW);
  digitalWrite(32, HIGH);
  digitalWrite(33, HIGH);
  digitalWrite(34, LOW);
  digitalWrite(35, LOW);}

if (tenhours==5){
  digitalWrite(29, LOW);
  digitalWrite(30, HIGH);
  digitalWrite(31, LOW);
  digitalWrite(32, LOW);
  digitalWrite(33, HIGH);
  digitalWrite(34, LOW);
  digitalWrite(35, LOW);} 

if (tenhours==6){
  digitalWrite(29, LOW);
  digitalWrite(30, HIGH);
  digitalWrite(31, LOW);
  digitalWrite(32, LOW);
  digitalWrite(33, LOW);
  digitalWrite(34, LOW);
  digitalWrite(35, LOW);} 

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy