Some codes for Grove-4-Digit Display

Grove is a modulated, ready-to-use tool set.
Much like Lego, it takes a building block approach to assembling electronics.

Moderators: lily.li, violet, jeremy882, crail.lyu969

Post Reply
User avatar
Jacket Chen
Staff
Staff
Posts: 659
Joined: Thu Jun 21, 2012 4:25 pm
Are you a staff member of seeedstudio?: yes
Which products/projects are your favorite?: Seeeduino Shields
Location: China

Some codes for Grove-4-Digit Display

Post by Jacket Chen » Fri Dec 28, 2012 4:39 pm

Hi, i want to show an analogical value from analogical pin, for exemple 924 on the 4 digit display. How can i do this ? How may I separate the units, the tens and hundreds ?
if you just want to display 924, it's very simple.

Code: Select all

  #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); 
}
Love little, love long.

User avatar
Jacket Chen
Staff
Staff
Posts: 659
Joined: Thu Jun 21, 2012 4:25 pm
Are you a staff member of seeedstudio?: yes
Which products/projects are your favorite?: Seeeduino Shields
Location: China

Re: Some codes for Grove-4-Digit Display

Post by Jacket Chen » Fri Dec 28, 2012 5:08 pm

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: Select all

#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);
}
Love little, love long.

User avatar
willty
Pre-kindergarten
Pre-kindergarten
Posts: 1
Joined: Sat Dec 29, 2012 7:34 am

Re: Some codes for Grove-4-Digit Display

Post by willty » Sat Dec 29, 2012 7:39 am

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 :twisted:

I make this :

Code: Select all

#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();
  }
}

Post Reply