Sorry, don't have a schematic but the code follows. As noted, the code works, (displaying time of day, temperature and humidity and, with an IR control to adjust the time); problem arises when switching display pin connections from digital pins to analogs. I wonder if the problem is in the SevSeg.h library??
/*Time of day clock showing hours & minutes plus temperature & humidity on 4 digit 7 segment display
Uses a no-block timer "millisDelay" so display can be continually refreshed (required for non-flicker o/p)
Uses IR remote reader to set current hours and minutes
Requires the following Arduino libraries (for temperature & humidity sensor):
- DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
- Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
*/
#include "DHT.h" //Humid & Temp sensor ("DHT")
#include <millisDelay.h> //Non-blocking delay library - for 2 second clock increment trigger
#include "SevSeg.h" //7 segment display //To display time, temperature & humidity
#include "IRremote.h" //IR receiver //For setting correct hours & minutes
int receiver = A0; // Signal Pin of IR receiver to Arduino Analog Pin A0
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
millisDelay clockDelay; //Initiate a delay object
SevSeg sevseg; //Initiate a seven segment controller object
#define DHTPIN A1 // Pin connected to the DHT sensor (use an AI as a DI as the display uses all the DI pins)
#define DHTTYPE DHT11 // DHT 11 type sensor
// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);
int hours;
int minutes;
int seconds;
int displaytime;
int countr;
float t;
float h;
void setup() {
Serial.begin(9600); // Initialize the serial printer (for debugging)
dht.begin(); // Initialize the DHT sensor
clockDelay.start(1000); // start a 1 sec delay (1,000 msec)
hours = 1; minutes = 0; seconds = 0; //Start with this time
countr = 0; //If countr = 0, display time; if = 1, display temperature; if = 2, display humidity (& switch at 1 second intevals)
byte numDigits = 4; //Set pin assignments for display
pinMode(A1, OUTPUT);
/*byte digitPins[] = {2, 3, 4, 5}; //Original example program arrangement
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
byte digitPins[] = {2, 5, 6, 13}; //Arrangement for connectors to go straight from display pins to Arduino w/o criss-crossing
byte segmentPins[] = {3, 7, 11, 9, 8, 4, 12, 10};
*/
byte digitPins[] = {A5, A2, A1, 13}; //Arrangement for top 6 display pins to connect to Arduino AI pins (to simplify & shorten wiring)
byte segmentPins[] = {A4, 7, 11, 9, 8, A3, 12, 10};
// All AIs work except A1 (and A0).
// variable below indicates that 4 resistors were placed on the digit pins.
// set variable to 1 if you want to use 8 resistors on the segment pins.
bool resistorsOnSegments = 0;
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins, resistorsOnSegments); //Initialize the display
sevseg.setBrightness(90); //Doesn't seem to change brightness much
irrecv.enableIRIn(); // Initialize the IR receiver
}
void loop() {
// Check if delay has timed out - if so, increment clock by 2 seconds & read temperature & humidity
if (clockDelay.justFinished()) { // Only returns TRUE once.
clockDelay.start(2000); // Restart delay - 2,000 ms
seconds = seconds + 2;
if (seconds == 60) {
seconds = 0; //Adjust minutes & hours accordingly
minutes = minutes + 1;
}
if (minutes == 60) {
minutes = 0;
hours = hours + 1;
}
if (hours > 12) {
hours = 1;
}
displaytime = hours * 100 + minutes; //Calculate time number to display
countr = countr + 1; //To display next value
if (countr == 3) {
countr = 0; //Ranges from 0 to 2
}
if (countr == 1) { // Read temperature - takes about 250 mseconds
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read temperature as Celsius (the default)
t = dht.readTemperature();
t = t * 0.96; // Correction factor (as compared to other thermometers)
}
if (countr == 2) { //Read humidity
h = dht.readHumidity();
h = h * .95; // Humidity correction factor
}
}
if (countr == 0) { //Display time (in hours & minutes)
sevseg.setNumber(displaytime, 2); // 2nd variable sets decimal point position (0 for RHS digit up to 3 for LHS digit)
sevseg.refreshDisplay(); // Must run repeatedly & rapidly for persistance of vision effect
}
if (countr == 1) { //Display temperature
sevseg.setNumber(t, 1); // 2nd variable sets decimal point position (0 for RHS digit up to 3 for LHS digit)
sevseg.refreshDisplay(); // Must run repeatedly & rapidly for persistance of vision effect
}
if (countr == 2) { //Display humidity
sevseg.setNumber(h, 0); // 2nd variable sets decimal point position (0 for RHS digit up to 3 for LHS digit)
sevseg.refreshDisplay();
}
if (irrecv.decode(&results)) { // Have we received an IR signal from remote control?
if (results.value == 0xFFA857) { //VOL- remote button
minutes = minutes - 1;
seconds = 0;
}
if (results.value == 0xFF629D) { //VOL+ remote button
minutes = minutes + 1;
seconds = 0;
}
if (results.value == 0xFF22DD) { // Fast backward
hours = hours - 1;
}
if (results.value == 0xFFC23D) { // Fast forward
hours = hours + 1;
}
irrecv.resume(); // receive the next IR value
}
}
Thanks for any suggestions!