Pages: [1]   Go Down
Author Topic: Countdown with TM1638  (Read 2442 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi i got an arduino nano and a TM1638  , i must make 5 minutes timer can someone help me?
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure. What exactly do you need help with, what have you done already, and what, specifically, do you want it to do? (5 minutes timer = something that beeps five minutes after a button is pressed? Or does it display the current time? Or do you want to make five timers that each count one minute?)
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have already assembled the system. The example programs are running fine.
The problem is that i do not understand how to program the TM1368
I just need a Timer that start 5min countdown on the display of the TM1368.

The timer should be like this:

00:00:00:00'
H, M , S, mS


Must start at:

00:05:00:00'

Countdown

00:03:15:01'

Untill

00:00:00:00

When it's 0 beep on pin (x)

Thank you for your help smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 650
Posts: 50833
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I typed TM1638 into the google search field. The 2nd hit:


http://code.google.com/p/tm1638-library/
Library, code, and pictures. What more do you need?
« Last Edit: November 03, 2011, 07:11:34 am by PaulS » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I typed TM1638 into the google search field. The 2nd hit:


http://code.google.com/p/tm1638-library/
Library, code, and pictures. What more do you need?

I already watched thhose videos, and i already got libraries, but how could they help me in making a countdown? 
I dont think i can figure out the code for countdown program from lybraries. If i'm wrong could you explain how to?

Thank you a lot.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 650
Posts: 50833
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The library has a method setDisplayToString(). Call it with a string, and it shows up.

Counting down from 5 minutes is easy, if you have an RTC. Do you?

If not, and you are willing to accept that the Arduino clock is not all that accurate at times, you can use millis() get the current "time". Subtract the start time, and you know how much time has elapsed.

Subtract the elapsed time from the time to count down to determine the remaining time.

Converting a number of milliseconds to got to minutes, seconds, and milliseconds is a matter of using the modulo operator (%).

Converting the number of minutes, seconds, and milliseconds to a string is simple matter of calling sprintf with the proper format specifiers. The resulting string can be passed to the setDisplayToString() function.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can i use this in some wat?

BTW i dont need precision at all. It's just a scenic matter

Quote
int min=0;
int hour=0;
int sec=0;
string set=null

cin >> set;
while(set!="Q")
{
 if(set=="H")
 {
 hour=hour++;
 if(hour>12)
 {
   hour=1;
 }
}
else if(set=="M")
{min=min++;
if(min>60)
{
 min=0;
 hour=hour++;
 if(hour>12)
 {
   hour=1;
  
  
 }
 else if(set=="s")
 {
   sec=sec++;
   if (sec>60)
   {
     hour=hour++;
     if(hour>12)
     {
       hour=1;
     }
     min=0;
   }
 }
}
countdown(min,hour,sec)
{
 while(min!=0&&sec!=0&&hour!=0)
 {
   delay 1000ms;
   sec=sec--;
   if(sec>1)
   {
     min=min--;
     if(min>1&&hour!=0)
     {
       min=59;
       hour=hour--;
       if (hour!=0&&min!=0)
       {
         sec=60;
       }
     }
   }
 }
if(min==0&&sec--0&&hour==0)
{
« Last Edit: November 11, 2011, 06:25:57 am by Piton » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 650
Posts: 50833
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can i use this in some wat?
Did you try that?

cin implies an input device. Look at your Arduino. Do you see a keyboard?

There in no string class on the Arduino. There is a String class, but why anyone would use it to hold a single character escapes me. A string, either, for that matter,

Code:
   delay 1000ms;
What is this supposed to do?

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just found this countdown on this forum, i didnt try to put this prog becuase is not made for tm1638
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I saw some library examples...i really dont understand why in all Arduino world everthing must be NOT EXPLAINED proprely, i mean let's look at this example..
Quote
Example

Display "00000033.":

module1.setDisplayToDecNumber(33, 1);

Display 15 in decimal with no dots and no leading zeroes:

module1.setDisplayToDecNumber(15, 0, false);

It's not specified what to put in voidsetup , its not specified what to put in voidloop , why someone that starts using arduino should know everything about anything? It' really really annoying, someone want to lern but it's quite impossible too, and no one explains how to do with the most important and difficult thing on arduino for a beghinner...

THE CODE!

No one explains you with written and compilable code... really dont understand...it's frustrating.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 650
Posts: 50833
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino is a computer. A small one, with limited memory, but a computer nonetheless. If needs to be programmed, like any other computer.

If you can't write a program, why did you buy an Arduino? If you have never programmed an Arduino to do simple things, like flash an LED, or write to the serial port, why did you buy those displays and jump off the deep end?

Think about what you are trying to do. You want to count down from 5 minutes to 0. This is really pretty simple. Set a variable to 300, since there are 300 seconds in 5 minutes. Once a second, subtract one from this variable.

After doing that, determine how many minutes and seconds remain. minutes = totalSeconds / 60 and seconds = totalSeconds - (minutes * 60). Not exactly rocket science.

Once you have two numbers (minutes and seconds) convert them to a string, using sprintf.
Code:
char buffer[20];
sprintf(buffer, "%d:%02d", minutes, seconds);

Now that you have a string, display it on your hardware. There is a simple function call to do this.

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did some small basic programming, but when i have a new library is like to start from all over.
For the logic of the program there is no problem, the problem is put all the logic in the arduino.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok i made the 300 sec countdown now i have two problems

Quote
#include <TM1638.h>
TM1638 module1(8, 9, 7);

void setup() {


}

void loop()
{
  int m=30000;
  int rit=9; //real 10msec on output

for(int i; i<m; i--)
{
module1.setDisplayToDecNumber(m , 0, true);
m=m--;
delay(rit);
}
}

Cannot put more than 30000 on timing.

Cannot put number on the position i want... and it's not explained on TM1638 libraryes.

Some advice?

PS: When the count arrives to 0 it gives me ERROR.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 650
Posts: 50833
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Cannot put more than 30000 on timing.
If you mean that you can not store more than 32767 in an int, this is true. So, don't use an int. Use something bigger.

Quote
PS: When the count arrives to 0 it gives me ERROR.
"It" does, huh. Care to explain what "it" is?

Code:
m=m--;
m-- is equivalent to m = m - 1. So, this code is equivalent to
m = m = m - 1;
Looks a little silly written this way, doesn't it?

Code:
for(int i; i<m; i--)
{
  module1.setDisplayToDecNumber(m , 0, true);
  m=m--;
  delay(rit);
}
Where is i initialized? i starts with some random value. The continuation condition is that this random value be less than m. As long as it is, the body of the if statement will be executed. Then, i will be decremented. But, in the body of the if statement, m is decremented, too.

I really don't see that i is serving any useful purpose, here. This would work better.
Code:
for(int m=300; m<=0; m--)
{
  module1.setDisplayToDecNumber(m , 0, true);
  delay(1000);
}
The display will me updated once a second. If you want to update it more often, reduce the delay and increase the initial value of m.

Quote
Cannot put number on the position i want... and it's not explained on TM1638 libraryes.
Where do you want to put the number, and where does it appear?


Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your advice...

Cause of TM1638 library limitation the displaynumber function put numbers allaways right oriented, and there is no index to change to make it splice or flip.

I made a 300.000msec counter but i would like to make a minute second msecond counter.

mm : ss : ms ms

But it's not possible with this module right now cause of libraryes limitation according to the creator of TM1638.  


ps:

Dont know why but with your method, without i the TM1638 is not showing anything...
« Last Edit: November 13, 2011, 09:21:31 pm by Piton » Logged

Pages: [1]   Go Up
Jump to: