It looks like you have a NOR gate now, albeit non-standard RTL input levels. TTL is two diode drops and HCMOS is Vcc/2 threshold.
The saturated gain of a transistor is only 10 to 20. So choose R values for a gain of 10 for reliable current switching.
CMOS NOR Gate
This is a simplified CMOS NOR gate with fancy triangular inputs running at 100 & 110 Hz to give a 10 Hz beat frequency on the output. Purpose is to show the linear input threshold. This uses n and p Mosfets to give low impedance for both output states, although the high side usually has a resistor to current limit it.
From a first look and a glance at the datasheet, generally speaking this seems fine. But the Arduino isn't exactly nippy at changing those outputs and while they are changing (with LE low), the outputs will also be changing. Could that be what you mean by "flashing" display? I'd guess that the display isn't really flashing per-se, it's just changing slowly enough for you to see it as a big mess.
I would suggest setting pin 8 HIGH to begin with - which will block any changes from the BCD pins - then changing all the BCD outputs and finally setting pin 8 LOW to reflect those changes. Then delay and loop. Something like this maybe:
Important note from your code: In C at least, & has lower precedence than !=. So the expression:
i & 0x1 != 0
resolved as if you'd typed:
i & (0x1 != 0)
which is:
i & 1
That's a trap I've seen before. Use brackets to clearly state what you mean and always do so where & and | is concerned, especially if there's an == or != nearby. I've changed it below:
...
for( int i = 0; i < 10; ++i )
{
digitalWrite( 8, HIGH );
digitalWrite( 2, ((i & 0x0001) != 0) ? HIGH : LOW );
digitalWrite( 3, ((i & 0x0002) != 0) ? HIGH : LOW );
digitalWrite( 4, ((i & 0x0004) != 0) ? HIGH : LOW );
digitalWrite( 5, ((i & 0x0008) != 0) ? HIGH : LOW );
digitalWrite( 8, LOW );
delay( 1000 );
}
Best Answer
This is because of the base current. The current comes from the signal source.
Also, note that the demonstrated schematic is simply wrong. The proper AND gate has to amplify the signal, so with similar technique you can only build NAND element. If you need AND - simply make one NAND and then invert the output signal once more.
simulate this circuit – Schematic created using CircuitLab