johnwasser:
For example:
// Bit maps for the seven segment display
const unsigned char Segments[] =
{
0b11000000, // 0
0b11001111, // 1
0b10100100, // 2
0b10000110, // 3
0b10001011, // 4
0b10010010, // 5
0b10010000, // 6
0b11000111, // 7
0b10000000, // 8
0b10000011, // 9
};
// List of digit select lines, least significant digit first
const unsigned char DigitPins[4] = {
14, 2, 3, 4}; // Anodes (HIGH for on, LOW for off)
const unsigned char SegmentPins[] = {5,6,7,8,9,10,11,12}; // Cathodes (LOW for on, HIGH for off)
void setup()
{
for (int i=0; i<4; i++)
{
pinMode(DigitPins[i],OUTPUT);
digitalWrite(DigitPins[i],LOW);
}
for (int i=0; i<8; i++)
{
pinMode(SegmentPins[i],OUTPUT);
digitalWrite(SegmentPins[i],HIGH);
}
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
void loop()
{
// Get time since last reset
unsigned long hundredths = millis() / 10;
unsigned long seconds = hundredths / 100;
unsigned long minutes = seconds / 60;
int hours = minutes / 60;
int clock;
// Display minutes:seconds up to 100 minutes, then hours/minutes
if (seconds < 100)
clock = (seconds % 100) * 100 + (hundredths % 100);
else
if (minutes < 100)
clock = (minutes % 100) * 100 + (seconds % 60);
else
clock = (hours % 100) * 100 + (minutes % 60);
// Clear all segments before enabling a digit
for (int s=0; s<8; s++)
{
digitalWrite(SegmentPins[s],HIGH);
}
// Display each digit, right to left
for (int i=0; i<4; i++)
{
// Peel a digit off the low end of the number
int digit = clock % 10;
clock /= 10;
// Blank the MSD if it is zero
if (i==3 && digit == 0)
{
for (int s=0; s<8; s++)
digitalWrite(SegmentPins[s],HIGH);
}
else
{
// Display the digit on the seven segments
unsigned char segments = Segments[digit];
for (int s=0; s<8; s++)
{
digitalWrite(SegmentPins[s], segments & 1);
segments >>= 1;
}
}
if (seconds < 100)
{
// Steady decimal point when showing seconds and hundredths
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}
else
if (minutes < 100)
{
// Steady colon when showing minutes and seconds
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
else
{
// Make the colon blink each second
digitalWrite(12, seconds & 1);
digitalWrite(13, seconds & 1);
}
// Turn on the digit briefly
digitalWrite(DigitPins[i], HIGH); // Select one digit
delay(3);
digitalWrite(DigitPins[i], LOW);
}
}
@johnwasser so nice of you to have written a code! But I don't really follow. I'm only understanding bits.
At the top, I'm guessing you are explaining what line of code to use for each number.
I have to look up what const unsigned char is.
Is it possible to describe it more specifik, or what could I google for? Don't meant to be rude, thanks again @johnwasser!