It's a little long (the sketch does all sorts of things), and I am debating how best to post the display bits... but here is the whole sketch (unfinished: after this I do the time setting etc):
/*
New Sketch with LED displays
And GY68 air pressure/temp meter plus dht11 temp/humidity meter and time
Code by Michael Willems
version 1.0
2021-08-21
*/
// -----------------------------------------------------------------------------------------
// INCLUDES AND DECLARATIONS:
// -----------------------------------------------------------------------------------------
#include <Wire.h> // for I2C communication
#include <DS3231.h> // for real-time clock
#include <Adafruit_BMP085.h> // for air pressure/temp meter
Adafruit_BMP085 bmp;
int temperature;
int barometer;
int oldtemperature = 0;
int oldbarometer = 0;
#include <dht11.h> //for temp sensor:
dht11 DHT11;
#define DHT11PIN 8
int temp2;
int humidity;
int oldtemp2 = 0;
int oldhumidity = 0;
/* Code for TM1637 4 digit 7 segment display with Arduino. More info: www.makerguides.com */
#include <TM1637Display.h>
#define CLK 2 // Define the connections pins for display 1
#define DIO 3
#define CLK2 4 // Define the connections pins for display 2
#define DIO2 5
#define CLK3 6 // Define the connections pins for display 3
#define DIO3 7
#define CLK4 9 // Define the connections pins for display 3
#define DIO4 10
// Create two display objects of type TM1637Display:
TM1637Display display = TM1637Display(CLK, DIO);
TM1637Display display2 = TM1637Display(CLK2, DIO2);
TM1637Display display3 = TM1637Display(CLK3, DIO3);
TM1637Display display4 = TM1637Display(CLK4, DIO4);
// Create array that turns all segments on:
const uint8_t data[] = {0xff, 0xff, 0xff, 0xff};
// Create array that turns all segments off:
const uint8_t blank[] = {0x00, 0x00, 0x00, 0x00};
// You can set the individual segments per digit to spell words or create other symbols:
const uint8_t done[] = {
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
SEG_C | SEG_E | SEG_G, // n
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
};
const uint8_t hPA[] = {
0x00, //
SEG_C | SEG_E | SEG_F | SEG_G, // h
SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, // P
SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G // A
};
const uint8_t rh[] = {
0x00, //
0x00, //
SEG_E | SEG_G, // r
SEG_C | SEG_E | SEG_F | SEG_G // h
};
const uint8_t dC[] = {
0x00, //
0x00, //
SEG_A | SEG_B | SEG_F | SEG_G, // [deg]
SEG_A | SEG_D | SEG_E | SEG_F // C
};
unsigned long counter; // for flashing on-board LED 13 with 1s frequency
unsigned long cyclecounter = 0; // to see how often the loop does its thing
unsigned count;
int onboardled = 13; // for heartbeat LED 13
//clock stuff:
DS3231 Clock;
boolean Century=false;
boolean h12;
boolean PM;
byte ADay, AHour, AMinute, ASecond, ABits;
boolean ADy, A12h, Apm;
char *dayString[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
int second,minute,hour,date,month,year,val,dow,temp3;
// -----------------------------------------------------------------------------------------
// THE SETUP (RUNS ONCE):
// -----------------------------------------------------------------------------------------
void setup() {
// put your setup code here, to run once:
pinMode(onboardled, OUTPUT);
Serial.begin(9600);
Wire.begin(); // Initiate the Wire library
delay(10);
counter = millis();
cyclecounter = 0; //for testing loops/second
// set up, and start, the air pressure detector:
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
// Set the brightness:
display.setBrightness(6);
display2.setBrightness(6);
display3.setBrightness(6);
display4.setBrightness(6);
// All segments on:
display.setSegments(data);
display2.setSegments(data);
display3.setSegments(data);
display4.setSegments(data);
delay(1000);
display.setSegments(done);
display2.setSegments(done);
display3.setSegments(done);
display4.setSegments(done);
delay(500);
display.clear();
display2.clear();
display3.clear();
display4.clear();
delay(500);
display.setSegments(dC);
display2.setSegments(hPA);
display3.setSegments(rh);
delay(3000);
display.clear();
display2.clear();
display3.clear();
display4.clear();
delay(500);
}
// -----------------------------------------------------------------------------------------
// THE LOOP:
// -----------------------------------------------------------------------------------------
void loop() {
//
// Let's see if it's time to update the screen/flash LED/etc:
//
if ((millis() - counter) > 1000) { //yes, it's time to do the once-a-second stuff!
counter = millis();
digitalWrite (onboardled,!(digitalRead(onboardled))); //the on-board heartbeat LED
count = (millis()/1000);
temperature = ((bmp.readTemperature())-1); //read temp from the chip & adjust
barometer = ((bmp.readPressure()/100)+5); //read pressure from the chip & adjust
DHT11.read(DHT11PIN);
temp2 = (DHT11.temperature); //read temp from DHT & adjust (not used)
humidity = (DHT11.humidity+5); //read humidity from DHT & adjust
//
// now display the values:
//
if (temperature != oldtemperature) {
display.showNumberDec (temperature, false, 4, 0);
oldtemperature = temperature;
}
if (barometer != oldbarometer) {
display2.showNumberDec (barometer, false, 4, 0);
oldbarometer = barometer;
}
if (humidity != oldhumidity) {
display3.showNumberDec (humidity, false, 4, 0);
oldhumidity = humidity;
}
uint8_t segto;
int value = 1244;
segto = 0x80 | display4.encodeDigit((value / 100)%10); display4.setSegments(&segto, 1, 1);
ReadDS3231();
cyclecounter = 0;
}
// now, any code that has to continously run (not just once a second):
cyclecounter = cyclecounter +1; //to facilitate counting the cycles/second
} //end of loop
// -----------------------------------------------------------------------------------------
// THE FUNCTIONS:
// -----------------------------------------------------------------------------------------
//------------------------------
// read and display time:
//------------------------------
void ReadDS3231() {
int second,minute,hour,date,month,year,pm;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12,PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();
temp3=Clock.getTemperature();
dow=Clock.getDoW();
display4.showNumberDec(minute, true, 2, 2);
display4.showNumberDecEx(hour, 0b01000000, true, 2, 0);
//------print line 1:----------------------------
Serial.print ("20");
Serial.print (year);
Serial.print('-');
if (month<10){
Serial.print("0"); // leading zero
}
Serial.print(month,DEC); // month
Serial.print('-');
if (date<10){
Serial.print("0"); // leading zero
}
Serial.print(date,DEC); // date
Serial.print(" ");
Serial.print(dayString[dow]); // day of week
Serial.println(" ");
//-------print line 2:---------------------------
if (hour<10) {
Serial.print("0");
}
Serial.print(hour,DEC);
Serial.print(':');
if (minute<10){
Serial.print("0");
}
Serial.print(minute,DEC);
Serial.println("----------");
Serial.print (temperature);
Serial.print (" - ");
Serial.print (temp2);
Serial.print (" - ");
Serial.print (temp3);
Serial.println (" <<< ");
}