61 lines
1.5 KiB
C
61 lines
1.5 KiB
C
#include <Adafruit_LEDBackpack.h> // Support for the Backpack FeatherWing
|
|
#include <Adafruit_GFX.h> // Adafruit's graphics library
|
|
#include <Adafruit_I2CDevice.h>
|
|
#include <SPI.h>
|
|
#include "ntp_time.h"
|
|
|
|
#define DISPLAY_ADDRESS 0x70
|
|
#define BRIGHTNESS 1
|
|
|
|
uint8_t brightness = BRIGHTNESS;
|
|
|
|
// Create display object
|
|
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
|
|
|
void setupDisplay() {
|
|
clockDisplay.begin(DISPLAY_ADDRESS);
|
|
clockDisplay.setBrightness(brightness);
|
|
}
|
|
|
|
void displayTime() {
|
|
int displayHour = hour();
|
|
int displayMinute = minute();
|
|
int displayValue = displayHour*100 + displayMinute;
|
|
|
|
// Print the time on the display
|
|
clockDisplay.print(displayValue, DEC);
|
|
|
|
// Add zero padding when in 24 hour mode and it's midnight.
|
|
// In this case the print function above won't have leading 0's
|
|
// which can look confusing. Go in and explicitly add these zeros.
|
|
if (displayHour == 0) {
|
|
clockDisplay.writeDigitNum(1, 0);
|
|
if (displayMinute < 10) {
|
|
clockDisplay.writeDigitNum(3, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
void changeBrightness(bool increase) {
|
|
increase ? brightness = (brightness+2) % 15 : brightness = (brightness-2) % 15;
|
|
}
|
|
|
|
void adjustBrightness() {
|
|
int currentHour = hour();
|
|
if (currentHour > 8 && currentHour < 17) {
|
|
brightness = 11;
|
|
} else {
|
|
brightness = 1;
|
|
}
|
|
}
|
|
|
|
void displayColon(bool on) {
|
|
clockDisplay.setBrightness(brightness);
|
|
clockDisplay.drawColon(on);
|
|
clockDisplay.writeDisplay();
|
|
}
|
|
|
|
void displayValue(int value) {
|
|
clockDisplay.print(value, HEX);
|
|
}
|