the Catalex Digital Tube display using the TM1637 chip using i2c
4 digit 7 segment display from Qifei using 2 cascaded 74HC595 shift registers
so, the code is difference
/* Digital Clock
Digital Clock with LED Display - 4 Digits x 7 Segments
Display Time, Temperature and Relative Humidity
V1.1 - 10.Fev.2016
*** Notes of revision V1.1 ***
- Translated the remarks/comments into English
- Added optional statements to show the Temperature in Fahrenheit Degrees (F)
*/
#include <Time.h> //Time Library
#include <DS1307RTC.h> //Real Time Clock Library
#include <Wire.h> //Auxiliary Library for DS1307RTC (Real-Time Clock) - Pins to Arduino UNO: A4 (SDA), A5 (SCL)
#include <dht11.h> //Temperature and Humidity Library
dht11 DHT; //Define the name DHT for the sensor of Temperature and Humidity
#define DHT11_PIN 11 //Sensor DHT11 conected to the pin 11 on Arduino
int clockPin = 8; // Pin 8 of Arduino connected in the pin 11 of 74HC595 (Clock)
int latchPin = 9; // Pin 9 of Arduino connected in the pin 12 of 74HC595 (Latch)
int dataPin = 10; // Pin 10 of Arduino connected in the pin 14 of 74HC595 (Data)
int hora, minuto, temp, umid;
int unidadeHora, unidadeMinuto, dezenaHora, dezenaMinuto;
int unidadeTemp, dezenaTemp, unidadeUmid, dezenaUmid;
unsigned long ti;
int chk; //Variable to read the sensor DHT11
//Digits Matrix - 0 a 9
byte num[] = {
B01111110, // Zero
B00110000, // One
B01101101, // Two
B01111001, // Three
B00110011, // Four
B01011011, // Five
B01011111, // Six
B01110000, // Seven
B01111111, // Eight
B01111011, // Nine
};
void setup() {
pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
setSyncProvider(RTC.get); // Update the time with data of RTC (Real Time Clock)
//setTime(15, 05, 00, 13, 02, 2016);
}
void loop() {
ti = millis(); // Initial time for the Timer of Hour/Time
while ((millis() - ti) < 3000) { //Timer of 3 seconds to show the Hour
hora = hour();
minuto = minute();
unidadeHora = hora % 10;
dezenaHora = hora / 10;
unidadeMinuto = minuto % 10;
dezenaMinuto = minuto / 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)
shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaHora]); //Set the Hour (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set DISPLAY 2
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeHora]); //Set the Hour (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 2); //Set DISPLAY 3
shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaMinuto]); //Set the Minute (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeMinuto]); //Set the Minute (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 4); //Set LED of dots
shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Set LEDs of double dots
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)
digitalWrite(latchPin, HIGH);
}
delay(500); //Wait for half second before go ahead to show the next feature
chk = DHT.read(DHT11_PIN); //Read data of sensor DHT11
ti = millis(); //Initial time for the Timer of Temperature
temp = DHT.temperature; //Reading the Temperature in Celsius degree (C)
//Optional calculation of Temperature in Fahrenheit degrees (F). Remove the comments ("//") of following statement to use it.
//temp = (temp*18+5)/10+32;
while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Temperature
unidadeTemp = temp % 10;
dezenaTemp = temp / 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)
shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaTemp]); //Set the Temperature (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set DISPLAY 2
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeTemp]); //Set the Temperature (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 2); //Set DISPLAY 3
shiftOut(dataPin, clockPin, LSBFIRST, ~B01100011); //Set the degree symbol []
digitalWrite(latchPin, HIGH);
//Show the Temperature in Celsius degrees (C)
//Set the following statements as comments with "//" to show the Temperature in Fahrenheit (F)
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, ~B01001110); //Set the symbol of Celsius [C]
digitalWrite(latchPin, HIGH);
//Show the Temperature in Fahrenheit degrees (F)
//Remove the indication of comments "//" on following statements to show the Temperature in Fahrenheit (F)
//digitalWrite(latchPin, LOW);
//shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
//shiftOut(dataPin, clockPin, LSBFIRST, ~B01000111); //Set the symbol of Fahrenheit [F]
//digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)
digitalWrite(latchPin, HIGH);
}
delay(500); //Wait for half second before go ahead to show the next feature
ti = millis(); //Initial time for the Timer of Humidity
umid = DHT.humidity; //Reading the Humidity
while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Humidity
unidadeUmid = umid % 10;
dezenaUmid = umid / 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1
shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaUmid]); //Set the Humidity (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set DISPLAY 2
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeUmid]); //Set the Humidity (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 2); //Set DISPLAY 3
shiftOut(dataPin, clockPin, LSBFIRST, ~B01100011); //Set the upper symbol of percentage [%] of Humidity
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, ~B00011101); //Set the lower symbol of percentage [%] of Humidity
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set Display 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)
digitalWrite(latchPin, HIGH);
}
delay(500); //Wait for half second before to restart
}