Pages: [1]   Go Down
Author Topic: Led Analog Clock  (Read 1036 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my original post: http://arduino.cc/forum/index.php/topic,89200.0.html
well, i've done some reading and think that i found a better way but I would like some people to look at the code before I spend more time finishing it.  For the description of the project, refer to the link for the original post. 
The leds will be in a 6 by 7 matrix to be controlled but each led will be wired out to a corresponding point around a circle. 
here is the code:

Code:

int rowPin1 = 13;
int rowPin2 = 12;
int rowPin3 = 11;
int rowPin4 = 10;
int rowPin5 = 9;
int rowPin6 = 8;

int colPin1 = 7;
int colPin2 = 6;
int colPin3 = 5;
int colPin4 = 4;

void setminled(int);


void setup() {

pinMode(rowPin1, OUTPUT);
pinMode(rowPin2, OUTPUT);
pinMode(rowPin3, OUTPUT);
pinMode(rowPin4, OUTPUT);
pinMode(rowPin5, OUTPUT);
pinMode(rowPin6, OUTPUT);

pinMode(colPin1, OUTPUT);
pinMode(colPin2, OUTPUT);
pinMode(colPin3, OUTPUT);
pinMode(colPin4, OUTPUT);

digitalWrite(rowPin1, LOW);
digitalWrite(rowPin2, LOW);
digitalWrite(rowPin3, LOW);
digitalWrite(rowPin4, LOW);
digitalWrite(rowPin5, LOW);
digitalWrite(rowPin6, LOW);

digitalWrite(colPin1, HIGH);
digitalWrite(colPin2, HIGH);
digitalWrite(colPin3, HIGH);
digitalWrite(colPin4, HIGH);
}

void loop()
{
  int timerval;
  int minutes;
  int hours;
  int i;
 
minutes = 0;
hours = 0;

// set initial time to 6:00

// fully define all the minute pins

digitalWrite(rowPin1, HIGH);
digitalWrite(colPin2, LOW);
digitalWrite(colPin3, LOW);


for(i=0; i>=0; i++)
{

  delay(120000);
  if(minutes > 29)
  {
    if(hours == 12)
       hours = 1;
    else
      hours++;
  minutes = 0;
 // set led mintues to 0

digitalWrite(colPin3, HIGH);
digitalWrite(colPin4, HIGH);
digitalWrite(colPin5, HIGH);
digitalWrite(colPin6, HIGH);
digitalWrite(colPin7, HIGH);

// clear hour leds
digitalWrite(colPin1, HIGH);
digitalWrite(colPin2, HIGH);

// add function call to set new hour value
}
  else
  {
    minutes++;
    // clear minutes leds
    digitalWrite(colPin3, HIGH);
    digitalWrite(colPin4, HIGH);
    digitalWrite(colPin5, HIGH);
    digitalWrite(colPin6, HIGH);
    digitalWrite(colPin7, HIGH);
   
    setminled(minutes);
    //create function to set minute leds based on last minute
  }
}

void setminled(minutes)
{
  if(minutes == 1)
   {
     digitalWrite(rowPin2, HIGH);
     digitalWrite(colPin3, LOW);
   }
   
   if(mintues == 2)
     {digitalWrite   //continue for minutes and hours


Logged

Canada
Offline Offline
Sr. Member
****
Karma: 0
Posts: 318
Sometimes teaching, always learning,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
for(i=0; i>=0; i++)
This will always be true. You are saying to continue the loop as long as i >= 0. It starts at 0, and goes up from there.

Code:
  delay(120000);
Don't use delay. Look at the Blink Without Delay example.

Also, I'm not sure how you have your LEDs hooked up. If it is a 6x4 matrix that is switched exclusively by the arduino, you need to set the pins you are not using to high-impedance (ie. as INPUT). If one row is HIGH, and all the columns are LOW, one row of LEDs will be on, not just a single one.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How about this?  And it is a 6 by 7 matrix. Sorry and thanks.

Code:

int rowPin1 = 13;
int rowPin2 = 12;
int rowPin3 = 11;
int rowPin4 = 10;
int rowPin5 = 9;
int rowPin6 = 8;

int colPin1 = 7;
int colPin2 = 6;
int colPin3 = 5;
int colPin4 = 4;
int colPin5 = 3;
int colPin6 = 2;
int colPin7 = 1;

// void setminled(int minutes);


void setup() {

pinMode(rowPin1, OUTPUT);
pinMode(rowPin2, OUTPUT);
pinMode(rowPin3, OUTPUT);
pinMode(rowPin4, OUTPUT);
pinMode(rowPin5, OUTPUT);
pinMode(rowPin6, OUTPUT);

pinMode(colPin1, OUTPUT);
pinMode(colPin2, OUTPUT);
pinMode(colPin3, OUTPUT);
pinMode(colPin4, OUTPUT);

digitalWrite(rowPin1, LOW);
digitalWrite(rowPin2, LOW);
digitalWrite(rowPin3, LOW);
digitalWrite(rowPin4, LOW);
digitalWrite(rowPin5, LOW);
digitalWrite(rowPin6, LOW);

digitalWrite(colPin1, HIGH);
digitalWrite(colPin2, HIGH);
digitalWrite(colPin3, HIGH);
digitalWrite(colPin4, HIGH);
}

void setminled(int)
{
  int minutes;
 
  if(minutes == 1)
   {
     digitalWrite(rowPin2, HIGH);
     digitalWrite(colPin3, LOW);
   }
   
   if(minutes == 2)
     digitalWrite(rowPin2, HIGH);
     //{digitalWrite   //continue for minutes and hours
}

void loop()
{
  int timerval;
  int minutes;
  int hours;
  int i;
 
  minutes = 0;
  hours = 0;

  // set initial time to 6:00

  // fully define all the minute pins

  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin2, LOW);
  digitalWrite(colPin3, LOW);


  for(i=0; i>=0; i++)
  {

    delay(120000);
    if(minutes > 29)
    {
      if(hours == 12)
        hours = 1;
      else
        hours++;
      minutes = 0;
     // set led mintues to 0

     digitalWrite(colPin3, HIGH);
     digitalWrite(colPin4, HIGH);
     digitalWrite(colPin5, HIGH);
     digitalWrite(colPin6, HIGH);
     digitalWrite(colPin7, HIGH);

     // clear hour leds
     digitalWrite(colPin1, HIGH);
     digitalWrite(colPin2, HIGH);

     // add function call to set new hour value
    }
    else
    {
       minutes++;
      // clear minutes leds
       digitalWrite(colPin3, HIGH);
       digitalWrite(colPin4, HIGH);
       digitalWrite(colPin5, HIGH);
       digitalWrite(colPin6, HIGH);
       digitalWrite(colPin7, HIGH);
   
      setminled(minutes);
    //create function to set minute leds based on last minute
    }
  }
}

Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34220
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
delay(120000);
Will not work. Look at the scope of variables, you have to give it a UL type.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how do i use the Unsigned Long exactly?  Where do I substitute it in?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

6x7 that would be 42 leds, doesn't make sence for a clock... at lease for me. But i'm really intrested in the whole led analog clock thing, i want to have a seriously large 132 led clock (bicolors for minutes and seconds and tricolors for hours. working my way up to that...
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
delay(120000);
Will not work. Look at the scope of variables, you have to give it a UL type.

delay(120000) compiles just fine.
This line will make your program stop for 2 minutes. Is this what you want?
Logged

Canada
Offline Offline
Sr. Member
****
Karma: 0
Posts: 318
Sometimes teaching, always learning,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
delay(120000) compiles just fine.
That's correct. The delay parameter is unsigned long, so 120000 shouldn't be a problem (other than you're wasting processing power...)
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Each led will represent 2 minutes so yes, i want to delay it two minutes.  Well if that is not the problem then could someone tell me what is because it is just getting stuck at 6:00 which is just the first command, it won't change at all.  thanks
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For testing purposes, replace delay(120000) with delay(500), for example. This way you will see things move a bit faster, if they move at all.
If you need help, you would also need to show a schematic or at least a photo of your setup if it on breadboard.
Logged

Pages: [1]   Go Up
Jump to: