i need more programming spaace

I am using an arduino mega2560r3 and i am making a digital clock and need more programming space i do not know if i can clean up my program or if i need a sd shield but anyway my code is in the attachment please help

clock.ino (80.9 KB)

You need to learn about arrays, for loops, bit-operations and functions for the code size problem
and timing without using delay to keep your sketch responsive.

There will be not much code left when done.

thank you i have looked it up and I could not find any good websites or videos that explained it well enough could you point me to a website or forum that could help me learn

This should be functional identical.

The bit patterns don't make much sense to me and most of the bist are always off.

const byte pattern[60][7] PROGMEM = {
  { 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 1
  { 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00 }, // 2
  { 0x03, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00 }, // 3
  { 0x05, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00 }, // 4
  { 0x06, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00 }, // 5
  { 0x06, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00 }, // 6
  { 0x03, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00 }, // 7
  { 0x07, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00 }, // 8
  { 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00 }, // 9
  { 0x27, 0x80, 0x16, 0x00, 0x00, 0x00, 0x00 }, // 10
  { 0x21, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00 }, // 11
  { 0x23, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00 }, // 12
  { 0x23, 0x80, 0x13, 0x00, 0x00, 0x00, 0x00 }, // 13
  { 0x25, 0x80, 0x11, 0x00, 0x00, 0x00, 0x00 }, // 14
  { 0x26, 0x80, 0x13, 0x00, 0x00, 0x00, 0x00 }, // 15
  { 0x26, 0x80, 0x17, 0x00, 0x00, 0x00, 0x00 }, // 16
  { 0x23, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00 }, // 17
  { 0x27, 0x80, 0x17, 0x00, 0x00, 0x00, 0x00 }, // 18
  { 0x27, 0x80, 0x13, 0x00, 0x00, 0x00, 0x00 }, // 19
  { 0xE7, 0x80, 0x66, 0x00, 0x00, 0x00, 0x00 }, // 20
  { 0xE1, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00 }, // 21
  { 0xE3, 0x00, 0x67, 0x00, 0x00, 0x00, 0x00 }, // 22
  { 0xE3, 0x80, 0x63, 0x00, 0x00, 0x00, 0x00 }, // 23
  { 0xE5, 0x80, 0x61, 0x00, 0x00, 0x00, 0x00 }, // 24
  { 0xE6, 0x80, 0x63, 0x00, 0x00, 0x00, 0x00 }, // 25
  { 0xE6, 0x80, 0x67, 0x00, 0x00, 0x00, 0x00 }, // 26
  { 0xE6, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00 }, // 27
  { 0xE7, 0x80, 0x67, 0x00, 0x00, 0x00, 0x00 }, // 28
  { 0xE7, 0x80, 0x63, 0x00, 0x00, 0x00, 0x00 }, // 29
  { 0xE7, 0x80, 0x36, 0x00, 0x00, 0x00, 0x00 }, // 30
  { 0xE1, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00 }, // 31
  { 0xE3, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00 }, // 32
  { 0xE3, 0x80, 0x33, 0x00, 0x00, 0x00, 0x00 }, // 33
  { 0xE5, 0x80, 0x31, 0x00, 0x00, 0x00, 0x00 }, // 34
  { 0xE5, 0x80, 0x33, 0x00, 0x00, 0x00, 0x00 }, // 35
  { 0xE5, 0x80, 0x37, 0x00, 0x00, 0x00, 0x00 }, // 36
  { 0xE3, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00 }, // 37
  { 0xE7, 0x80, 0x37, 0x00, 0x00, 0x00, 0x00 }, // 38
  { 0xE7, 0x80, 0x33, 0x00, 0x00, 0x00, 0x00 }, // 39
  { 0xC7, 0x81, 0x16, 0x00, 0x00, 0x00, 0x00 }, // 40
  { 0xC1, 0x81, 0x10, 0x00, 0x00, 0x00, 0x00 }, // 41
  { 0xC3, 0x01, 0x17, 0x00, 0x00, 0x00, 0x00 }, // 42
  { 0xC3, 0x81, 0x13, 0x00, 0x00, 0x00, 0x00 }, // 43
  { 0xC5, 0x81, 0x11, 0x00, 0x00, 0x00, 0x00 }, // 44
  { 0xC6, 0x81, 0x13, 0x00, 0x00, 0x00, 0x00 }, // 45
  { 0xC6, 0x81, 0x17, 0x00, 0x00, 0x00, 0x00 }, // 46
  { 0xC6, 0x81, 0x10, 0x00, 0x00, 0x00, 0x00 }, // 47
  { 0xC7, 0x81, 0x17, 0x00, 0x00, 0x00, 0x00 }, // 48
  { 0xC7, 0x81, 0x13, 0x00, 0x00, 0x00, 0x00 }, // 49
  { 0xC7, 0x81, 0x36, 0x00, 0x00, 0x00, 0x00 }, // 50
  { 0xC1, 0x81, 0x30, 0x00, 0x00, 0x00, 0x00 }, // 51
  { 0xC3, 0x01, 0x37, 0x00, 0x00, 0x00, 0x00 }, // 52
  { 0xC3, 0x81, 0x33, 0x00, 0x00, 0x00, 0x00 }, // 53
  { 0xC5, 0x81, 0x31, 0x00, 0x00, 0x00, 0x00 }, // 54
  { 0xC6, 0x81, 0x33, 0x00, 0x00, 0x00, 0x00 }, // 55
  { 0xC6, 0x81, 0x37, 0x00, 0x00, 0x00, 0x00 }, // 56
  { 0xC3, 0x81, 0x30, 0x00, 0x00, 0x00, 0x00 }, // 57
  { 0xC7, 0x81, 0x37, 0x00, 0x00, 0x00, 0x00 }, // 58
  { 0xC7, 0x81, 0x33, 0x00, 0x00, 0x00, 0x00 }, // 59
  { 0x67, 0x83, 0x76, 0x01, 0x00, 0x00, 0x00 }, // 1:00
};

unsigned long lastAdvance;
unsigned int index = 0;

void setPins(int selPattern) {
  for (unsigned int i = 0; i <= A2; i++) {
    digitalWrite(i, pgm_read_byte(&pattern[selPattern][i >> 3]) & (1 << (i & 7)));
  }
}

void setup() {
  for (byte i = 0; i <= A2; i++) {
    pinMode(i, OUTPUT);
  }
  setPins(index);
}

void loop() {
  if (millis() - lastAdvance >= 1000) {
    lastAdvance += 1000;
    if (++index >= (sizeof(pattern) / sizeof(pattern[0]))) {
      index = 0;
    }
    setPins(index);
  }
}
1950 Bytes (0%) Flash, maximum is 253952 Bytes.
15 Bytes (0%) RAM, 8177 Bytes remaining, maximum is 8192 Bytes.

garretdantin:
thank you i have looked it up and I could not find any good websites or videos that explained it well enough could you point me to a website or forum that could help me learn

On every page of this forum you should see a green bar with words across it.
One of them is LEARNING. Have you tried it?

There are soooo many pins whose state never changes. 5-10mins of find/replace got your exact code down to:

Sketch uses 8,360 bytes (3%) of program storage space. Maximum is 253,952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8,183 bytes for local variables. Maximum is 8,192 bytes.

That's without the optimisation Whandall has also provided.

For all of the pins that are always low, can't you just tie them to ground?

OP's code is horrifically inefficient and scales very poorly - whandall posted the Right Way to fix it.

BUT it only compiles to 27kb. The Mega 2560 has 256kb of flash. You were miles from the limit...