Grove Examples > 4-Digit-Display

Example 04: Display (4-Digit-display)

Example Video

Code

Find the latest and greatest code example HERE on GitHub.

/*
  4 digital-display  
 This example code is in the public domain.
 */
#include "TM1637.h" 

/* Macro Define */
#define CLK               9                  /* 4-digital display clock pin */
#define DIO               10                 /* 4-digiral display data pin */
 
/* Global Varibles */
TM1637 tm1637(CLK, DIO);                  /* 4-digital display object */

/* the setup() method runs once, when the sketch starts */
void setup() {
    /* Initialize 4-digital display */
    tm1637.init();
    tm1637.set(BRIGHT_TYPICAL); 
}

/* the loop() method runs over and over again */
void loop() {   
  int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F
  int8_t ListDisp[4];
  unsigned char i = 0;
  unsigned char count = 0;
  delay(150);
  while(1)
  {
    i = count;
    count ++;
    if(count == sizeof(NumTab)) count = 0;
    for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++)
    {
      ListDisp[BitSelect] = NumTab[i];
      i ++;
      if(i == sizeof(NumTab)) i = 0;
    }
    tm1637.display(0,ListDisp[0]);
    tm1637.display(1,ListDisp[1]);
    tm1637.display(2,ListDisp[2]);
    tm1637.display(3,ListDisp[3]);
    delay(300);
  }
}

Grove Starter Kit Home