Stopwatch with ATtiny13 and TM1637 LED Module

Full code on GitHub: https://github.com/taunoe/ATtiny13-Stopwatch

7-segment display module based on TM1637 chip
7-segment display module based on TM1637 chip
ATtiny 13 pinout
ATtiny 13 pinout

If you have 5v power source you do not need to build the LM7805 Voltage regulator circuit as in the drawing.

kuvatommis_2018-02-22_19-23-01_x88kqTJ80s.jpeg

img_20180222_201822_YJ1DzRkMZC

Code

Download TM1637 Libraryhttps://github.com/lpodkalicki/attiny-tm1637-library/and put files in same folder with code.

hgfhs_zr3NLz8KTB

Arduino code:

That how long is 1 second may need manual calibration. For now it is 90m/s.

_delay_ms(90); //

/*
* ATtiny timer with TM1637 display
* Tauno Erik
* 18.02.2018
* 
*/
#include 
#include <avr/io.h>
#include <util/delay.h>
#include "tm1637.c" 
int main(void)
{
 uint8_t    i = 0; // Display 1 num right to left
 uint8_t   ii = 0; // Display 2 num right to left
 uint8_t  iii = 0; // Display 3 num right to left
 uint8_t iiii = 0; // Display 4 num right to left
 PORTB |= (1 << PB4); // enable start/stop button
 TM1637_init(); 
 while (1)
 {
 int BUTTON = PINB;
 if(!(BUTTON&0b00010000)){
   /*When Button is ON */
   // Display 1 num right to left
   TM1637_display_digit(TM1637_SET_ADR_03H,i % 0b00001010);
   // Display 2 num right to left
   if(i > 9 && ii==0){
     ii = i-9;
     TM1637_display_digit(TM1637_SET_ADR_02H, ii % 0b00001010);
     i = 0;
   }else if(i > 9 && ii > 0){
     ii++;
     TM1637_display_digit(TM1637_SET_ADR_02H, ii % 0b00001010);
     i = 0;
   }
   // Display 3 num right to left
   if(ii > 9 && iii==0){
     iii = ii-9;
     TM1637_display_digit(TM1637_SET_ADR_01H, iii % 0b00001010);
     ii = 0;
   }else if(ii > 9 && iii > 0){
     iii++;
     TM1637_display_digit(TM1637_SET_ADR_01H, iii % 0b00001010);
     ii = 0;
   }
   // Display 1 num right to left
   if(iii > 9 && iiii==0){
     iiii = iii-9;
     TM1637_display_digit(TM1637_SET_ADR_00H, iiii % 0b00001010);
     ii = 0;
   }else if(iii > 9 && iiii > 0){    
     TM1637_display_digit(TM1637_SET_ADR_00H, iiii % 0b00001010);
     iiii++;
     iii = 0;
   }
   _delay_ms(90);//
   i++;
 }else{
 /*When Button is OFF */ 
 }
 }//while loop end
}//main end

Demo

2 Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.