Wiring a Digital LED Display and a Touch TFT to the Same Mega2560

I'm having a lot of trouble getting this to work. I'd like to set up the project in such a way that I have my touch shield and a 4-digit digital led display hooked up onto the same Mega 2560, but the way the digital displays work (power on pin x lights up line x) interferes with the power to the touch screen that I'm using. I'm sure this is an electrical problem, but I suppose it could also be a conceptual problem. Any advice on an approach to take that would allow me to hook up both? Would I be better off displaying the numbers onto a separate lcd panel instead of a digital LED display? Am I way off course?

Description is too vague. Provide more details of the hardware, either in use now or intended.

Hardware information:
Board: Sainsmart Mega 2560 from kit. SainSmart Uno R3 Starter Kit – SainSmart.com
Touchscreen: ITEAD 3.2" TFT LCD Touch Shield http://imall.iteadstudio.com/im120417021.html
LED Digital Number Display from same Sainsmart kit. Currently using the single digit display.
I have recently discovered that the wiring diagram that I was following to wire the LED number display was incorrect, so I'm currently working on rewiring that to see if that helps. I'm still thinking that the concept may be flawed by virtue of the fact that, if the LED display needs a pin to be powered off and my touch shield needs the power on, that both states cannot coexist. I'm assuming that I will either need to use something to direct current as needed when provided with constant current (is that a thing?) or switch to an LCD shield. The end goal is to use the touch shield to interface with the program and then have timing or counting information displayed on both the LCD Touchscreen as well as the digital display. The code I'm using for the Digital display is as follows, and I'm trying to mesh that with separate code for the touchscreen.

int a=7;  //Top Horizontal
int b=6;  //Top-Right
int c=5;  //Bottom-Right
int d=11;  //Bottom Horizontal
int e=10;  //Bottom-Left
int f=8;  //Top-Left
int g=9;  //Middle Horizontal
int dp=4; //Decimal Point

//display number0
void digital_0(void)
{
  unsigned char z;
  for(z=4;z<=8;z++)
  digitalWrite(z,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(g,LOW);
}

//display number1
void digital_1(void)
{
  unsigned char z;
  digitalWrite(c,HIGH);// pin5 high, light up c
  digitalWrite(b,HIGH);//light up b
  for(z=7;z<=11;z++)//go out else
    digitalWrite(z,LOW);
    digitalWrite(dp,HIGH);//light up decimal point dp
}

//display number2
void digital_2(void)
{
  unsigned char z;
  digitalWrite(b,HIGH);
  digitalWrite(a,HIGH);
  for(z=9;z<=11;z++)
    digitalWrite(z,HIGH);
    digitalWrite(dp,HIGH);
    digitalWrite(c,LOW);
    digitalWrite(f,LOW);
}

// display number3
void digital_3(void)
{
  unsigned char z;
  digitalWrite(g,HIGH);
  digitalWrite(d,HIGH);
  for(z=5;z<=7;z++)
    digitalWrite(z,HIGH);
  digitalWrite(dp,HIGH);
  digitalWrite(f,LOW);
  digitalWrite(e,LOW);
}

// display number4
void digital_4(void)
{
  digitalWrite(c,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
  digitalWrite(dp,HIGH);
  digitalWrite(a,LOW);
  digitalWrite(e,LOW);
  digitalWrite(d,LOW);
}

// display number5
void digital_5(void)
{
  unsigned char z;
   for(z=7;z<=9;z++)
    digitalWrite(z,HIGH);
   digitalWrite(c,HIGH);
   digitalWrite(d,HIGH);
   digitalWrite(dp,HIGH);
   digitalWrite(b,LOW);
   digitalWrite(e,LOW);
}

// display number6
void digital_6(void)
{
  unsigned char z;
  for(z=7;z<=11;z++)
    digitalWrite(z,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(dp,HIGH);
  digitalWrite(b,LOW);
}

// display number7
void digital_7(void)
{
  unsigned char z;
  for(z=5;z<=7;z++)
    digitalWrite(z,HIGH);
  digitalWrite(dp,HIGH);
  for(z=8;z<=11;z++)
    digitalWrite(z,LOW);
}

// display number8
void digital_8(void)
{
  unsigned char z;
  for(z=5;z<=11;z++)
    digitalWrite(z,HIGH);
  digitalWrite(dp,HIGH);
}

//digital number9
void digital_9(void)
{
  unsigned char z;
  digitalWrite(g,HIGH);
  digitalWrite(d,HIGH);
  for(z=5;z<=7;z++)
    digitalWrite(z,HIGH);
  digitalWrite(dp,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(e,LOW);
}

void setup()
{
  int i;//define i
  for(i=4;i<=11;i++)
    pinMode(i,OUTPUT);//set pin4~pin11 output
}
void loop()
{
  while(1)
  {
    digital_0();//display 0
    delay(1000);//delay 1s
    digital_1();
    delay(1000);
    digital_2();
    delay(1000);
    digital_3();
    delay(1000);
    digital_4();
    delay(1000);
    digital_5();
    delay(1000);
    digital_6();
    delay(1000);
    digital_7();
    delay(1000);
    digital_8();
    delay(1000);
    digital_9();
    delay(1000);
  }
}

Ok, looks like the touch screen uses quite a few pins!
Leaving you 23 pins available, which is plenty to either drive a 7-segment display directly - sinking our sourcing current to each segment.
Or using shiftOut to send data to a shift register using any 3 free pins.
Could also use SPI to send data out, connecting to SCK, MOSI, and using any one of the free pins for the chip select/output register clock.
Looks like the shield goes over all headers. These is a great example for using my Mega/Due/MegaADK/EtherMega screw shield:
http://www.crossroadsfencing.com/BobuinoRev17/


Arduino Mega PIN Description

D0, D1 - free, keep open for serial downloads

D2 T_IRQ
D3 T_DOUT
D4 T_DIN
D5 T_CS
D6 T_CLK

D7,8,9,10,11,12,13 - 7 free
D14,15,16,17,18,19,20, 21 - 8 free

D22 DB8
D23 DB9
D24 DB10
D25 DB11
D26 DB12
D27 DB13
D28 DB14
D29 DB15
D30 DB7
D31 DB6
D32 DB5
D33 DB4
D34 DB3
D35 DB2
D36 DB1
D37 DB0
D38 RS
D39 WR
D40 CS
D41 RST

D42,43,44,45,46,47,48,49 - 8 free

D50 SD_MISO
D51 SD_MOSI
D52 SD_SCK
D53 SD_NSS

So out of this group, I'd suggest you change 4-5-6 to other free pins.

int a=7; //Top Horizontal
int b=6; //Top-Right
int c=5; //Bottom-Right
int d=11; //Bottom Horizontal
int e=10; //Bottom-Left
int f=8; //Top-Left
int g=9; //Middle Horizontal
int dp=4; //Decimal Point

And then set the pins in an array:

byte pinArray[] = {14,15,16,17,18,19,20,21,}; // as an example for DP-g-f-e-d-c-b-a

loop thru the array in setup for pinModes
for (x=0; x<8; x=x+1){
pinMode(x, OUTPUT);
}

Create font definitions
byte fontArray[] = {
0b00111111, // 0, with 7,6,5,4,3,2,1,0 = DP,g,f,e,d,c,b,a.  1 = on in this example
0b00000110, // 1
0b01011011, // 2
etc
0b011011111, // 9
};
then when ready to send data:
using an external shift register in loop:
digitalWrite (latchpin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, fontArray[dataByteToDisplay]);
digitalWritee (latchPin, HIGH);

or loop thru the bits and set the outputs HIGH & LOW as needed using this masking array to look at each bit:
byte maskArray[] = {
0b00000001,
0b00000010,
0b00000100,
0b00001000,
0b00010000,
0b00100000,
0b01000000,
0b10000000,
};
for (x=0; x<8; x=x+1){
   if ((maskArray[x] & fontArray[dataByteToDisplay]) == 0){
   digitalWrite (pinArray[x], LOW);
   }
   else {
    digitalWrite (pinArray[x], HIGH);
   }
}

Lots of ways to go thru data and decide how to display it, using arrays seems pretty efficient & effective to me. Define the arrays in the pre-setup area of your code so they're global, if you need to tweak to change pins or font definition or whatever, they're all in one place.

I just realized after reading your reply (which is extremely helpful! Thank you so much!) that I linked the wrong kit. I'm not using the UNO R3, I'm using the Mega 2560 Mega 2560 R3 Starter Kit | SainSmart – SainSmart.com in this kit. Whoops. The concept, I'm sure, still applies. I was searching around my board for these extra 23 pins and I was only able to find 16, and I was terribly confused until I checked my last post. So sorry about that. <_< I assume all the same concepts hold, though I'm still extremely new to this so I'm not sure if there are going to be any major problems using the pins on the inside of the board, instead of the PWM pins I was using before.

Again, I apologize if these questions seem low-brow or anything. I'm teaching myself all of this in a hurry. My background includes some minor coding experience, but it's been a few years so I'm even having to refresh on the basics. XD I'm having a blast so far though!

Is the touchscreen the same, using all pins listed? Then it should work with the Mega clone/ripoff.

The pins should be the same. The LCD Touch Shield takes up all but 4 of the pins on the outside, 3 of which appear unlabeled (2 above the GND with the PWM 1-13 pins, one next to the IOREF pin) and the other is the IOREF pin. On the inside, I've got the 4 holes labeled JP5, the 6 pins adjacent to the JP5 holes, and 6 pins with the label ICSP. I'm assuming some of these other points on the board (such as those labeled TX, RX, and L) can be soldered to to make connections, but I'm worried about messing things up on the board, not being able to access the pins for programming purposes, or not using pins that will function with the devices I hook into them.

I'm really a beginner at this, and the schematics on this http://arduino.cc/en/uploads/Main/arduino-mega2560_R3-sch.pdf page are, I'm sure, the information I'm looking for, but I'm a bit over my head. Any recommendations on where to start with all this? I feel like I may have bitten off more than I can chew.

Yes, I'd recommend getting a screw shield, or another breakout board, so you can access the pins that the shield does not use according to they link you provided.
D7,8,9,10,11,12,13 - 7 free
D14,15,16,17,18,19,20, 21 - 8 free
D42,43,44,45,46,47,48,49 - 8 free

The ICSP header in the middle connects to SCK, MISO, MOSI, and Reset,+5, Gnd.

Would something like this be reasonable? http://www.nkcelectronics.com/megashield-kit.html Or thishttp://www.fasttech.com/products/1009/10001547/1115501? And, if so, is there any way to do something like that without adding quite so much thickness to the build?

Or do you mean something like this https://www.tindie.com/products/jkdevices/atmega2560-breakout-board-arduino-compatible-16mhz-5v/, which I found just googling breakout boards, and, if so, how does something like this attach/work?
I found a bit more out about breakout boards after continued searches, and I see how that would be perfect, especially since I've already soldered a second connection to each of the external pins on the 2560, so that I could breadboard and use the LCD touch shield at the same time. I wouldn't know where to begin to find the right kind of breakout board for this project, but I will keep looking. Thank you so much.

I was looking for the screw shields as well, which I see in your attached image from earlier, but I am having one heck of a time finding any. I eventually found this one Cross Roads Electronics, which appears to be the same one in your picture, but they want as much for the screw shield as I paid for the Mega 2560 itself. <_< This hurts my wallet. In this case, the screw shield appears to be almost identical in function to what I've already done to my board, I just have to add the last row of pins for the double row on the board. I soldered onto the bottom side of the board, was that a mistake?

The first one you linked to looks like it would do the job - except:
Availability: Discontinued

The second one might work, all the connections would be under the screen tho.

The 3rd one, that is just the processor and could not be used.

Sorry if my screw shield is too expensive, that's what they sell for.
Kits are $35, you can save some $ and assemble it yourself.
Mega's are $45

unless you got a clone somewhere.

Your picture is very dark, can't tell what you've done there.

Not too worried about the cost of the screw shield, I was just trying to find some way to do something similar using what I already had, hence the picture. Did not mean to offend. I did not realize you had posted a link to the board, or that you were the manufacturer, so my apologies. I meant it as a light-hearted aside.

Picture quality is, admittedly, incredibly low. Basically, what I've done is taken those connectors you see coming off the side of the board and soldered them to the soldering points of the pins on the bottom of the board, so that I could lay the lcd shield on the board, but still wire other things to the board. Maybe this is a better representation:

But, this still does not give me an easily accessible way to ad many extra points of contact in a easily distinguishable fashion, as your screw shield does. How would I go about wiring something like that? Obviously, I can simply branch off of points, as I've done, to add many connections, but how does this affect the project from a software standpoint? As with the Digital LED reader, how would I turn on and off those branches without turning off other branches, so to speak? They way I'm currently wiring, I am only using the external 86 pins, albeit multiple times, and from a software standpoint this makes it impossible to wire anything that requires power to be off to a pin with the touch shield requiring constant power from 82 of the 86 pins. Basically, how does the screw shield work? And how would I program it if I did order something like that?

EDIT: Also, I am working with a clone made by SainSmart, whose tutorials, guides, and customer service appear less-than-knowledgable. For example, I spent over an hour changing their code for the digital led counter, which assigned the pins incorrectly, said LOW for every single time it meant HIGH, and did not have the ground wired. Would this affect my compatibility with potential expansion boards?

EDIT2: I think I only just now comprehended your previous post, with the picture of your screw shield. Are you saying that, despite the fact that the LCD Touch shield has a pin in the sockets (ex: D7-13) that it is not using those pins for anything? If that is the case, that would solve my problem in an instant!

Ok, so update.

I got the wiring to work with the array and the correct pin configuration, which is fantastic! Now, the next step.

I got the single digit display to work, now it's time to try to get the 4-digit display to work, which is where I am stuck again. The single digit display works perfectly well, and the touch works great, even with the 4-digit display drawing power. The 4-digit display has 12 pins instead of 10, but that was a simple adjustment, and I was even able to use the same code from the single-digit to test it out, which works marvelously, I might add, if you ignore the fact that I burnt out 4 of the leds while trying to test for common cathodes. <_<

Now, when it comes to programming this 4-digit display, I am currently researching different methods, but if anybody has any input they'd like to add I would certainly appreciate it!

EDIT: Also, CrossRoads, or anyone else who know the answer, when you were talking about arrays earlier, you mentioned creating font definitions. I'm a little confused as to how you would implement the definitions into the code. What I mean to say is, how do I make the program output 0b00111111 as definitions for pin power? I have the pins defined in an array already, and I'm able to set them HIGH or LOW individually or in groups using for loops, but the method you describe looks so clean I can find no reason not to use it, if I only knew how!