Some codes for Grove-4-Digit Display

if you just want to display 924, it’s very simple.

[code] #include <TimerOne.h>
#include “TM1637.h”

int8_t TimeDisp[] = {0x00,0x00,0x00,0x00};

#define CLK 2
#define DIO 3
TM1637 tm1637(CLK,DIO);

void setup()
{
tm1637.set();
tm1637.init();
}
void loop()
{
int Value=924; //You can change this Value
TimeDisp[3]=Value%10;
TimeDisp[2]=Value%100/10;
TimeDisp[1]=Value%1000/100;
TimeDisp[0]=Value/1000;
tm1637.display(TimeDisp);
}[/code]

And if you want to show an analogical value from analogical pin, it’s code depend on the product what you need to use.

like a Grove - Temperature and Humidity Sensor Pro, we can display its’ humdity or temperature. for example: Current humdity = 62.1% , it’ll display 0621.

[code]#include <SoftwareSerial.h>
#include <TimerOne.h>
#include “TM1637.h”
#define DHT11_PIN 14

int8_t TimeDisp[] = {0x00,0x00,0x00,0x00};

#define CLK 2
#define DIO 3
TM1637 tm1637(CLK,DIO);

byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++){
while(!digitalRead(DHT11_PIN));
delayMicroseconds(30);

if(digitalRead(DHT11_PIN)) 
  result |=(1<<(7-i));
while(digitalRead(DHT11_PIN)); 

}
return result;
}

void setup()
{
pinMode(DHT11_PIN,OUTPUT);
Serial.begin(9600);
tm1637.set();
tm1637.init();
}

void loop()
{
byte dht11_dat[5];
byte dht11_in;
byte i;
float humdity,temperature;

digitalWrite(DHT11_PIN,LOW);
delay(18);

digitalWrite(DHT11_PIN,HIGH);
delayMicroseconds(40);

pinMode(DHT11_PIN,INPUT);
delayMicroseconds(160);
for (i=0; i<5; i++)
dht11_dat[i] = read_dht11_dat();

pinMode(DHT11_PIN,OUTPUT);
digitalWrite(DHT11_PIN,HIGH);
humdity=((float)(dht11_dat[0]*256+dht11_dat[1]))/10;
//temperature=((float)(dht11_dat[2]256+dht11_dat[3]))/10;
Serial.print("Current humdity = “);
Serial.print(humdity,1);
Serial.print(”% ");
int Value;
Value=humdity
10;
TimeDisp[3]=Value%10;
TimeDisp[2]=Value%100/10;
TimeDisp[1]=Value%1000/100;
TimeDisp[0]=Value/1000;
tm1637.display(TimeDisp);
delay(1000);
}[/code]

Thank you !
I like very much grove stuff, i will use grove system in my classroom (i’m teacher in France). I want to make a block for ArduBlock for grove 4 digit display :smiling_imp:

I make this :

[code]#include “TM1637.h”
#define CLK 2//pins definitions for TM1637 and can be changed to other ports
#define DIO 3
TM1637 tm1637(CLK,DIO);
void setup()
{
Serial.begin(9600);

tm1637.init();
tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
}
void loop()
{
static unsigned long t = 0;//Refreshment of the display quite 250ms
if(millis() - t > 250)
{
tm1637.display(0,(analogRead(A0) / 1000) % 10); //Display of thousands
tm1637.display(1,(analogRead(A0) / 100) % 10); //Display of hundreds
tm1637.display(2,(analogRead(A0) / 10) % 10); //Display of tens
tm1637.display(3,analogRead(A0) % 10); //Display of units
Serial.print( analogRead(A0) ); // Show the value of A0 on the serial port
Serial.println("");

t = millis();

}
}[/code]