What i see when pin 4 goes high there is minimal voltage on it only like 1-2 volts. if i change the pin to 12 or any other pin there is no issue. I duplicated this on 2 seperate arduinos. and this is with no shield just measuring the the voltage on the pin.
there really isnt. I was using a shield. and part of it wasnt working.
After tracing everything out i detected that pin4 was going high but just barely. So i simplified the code down to the bare minimum and posted it here.
I then uploaded it to someone elses board and found the same thing.
They then expanded the program to try out 3-4 interfaces and saw the same thing.
We checked it with a meter, any pin but 4 would go high for a second and read 5v.
pin 4 would go high and read about 1.5. ALso wanted to note that all testing was done on a bare arduino no shield attached.
Again most bizarre. I just now of course loaded your sketch into my serial clone arduino (with the same shield connector layout) and of course I get 0v for a sec and 4.98v for a sec.
Another poster here stated they also saw no problem when trying your code. So we know the code is good and at least two of us can't duplicate your symptom.
So I guess your next step, if you have a steady hand is try and measure the output right at the 168 chip, which is pin 6 (TO) PD4 at it's socket location. You will need a sharp point on your meter lead. If it's good there then you may have have a high resistance solder joint or intermittent broken trace at the shield connector pin 4, or just making bad contact to the pin4 socket hole.
If it still measures bad right at the chip's pin then the next test is tricky but required. Power off the board and pull the 168 out of it's socket, then gently bend it's pin 6 straight out. Reinsert the chip, re-power the board and measure it's pin six again. If it's still bad then the 168 chip's pin busted, however if it then reads good then you have some kind of partial short circuit on the boards tracing or the pin 4 connector, causing excessive current to flow forcing the pin's output voltage to lower.
PS: The most bizarre part is you finding a friends board doing the same thing. However we can only troubleshoot one board at a time. Is it possible a shield is warped or misaligned somehow and is damaging the inside of the pin4 socket on the Arduinos? Just a WAG. I guess it's also possible that when you added the shield board some component or wiring error on the sheild caused too much current to be drawn from pin4, damaging it. Did your friends Arduino have your shield plugged into it at any prior time?
i'm "the other guy" who can confirm what soco is claiming... he first showed us that pin 4 was registering far below 5V, then reduced that sketch to a bare minimum, but the results were the same... we used my board and received the same results... i even loaded the example "Blink" sketch, changed to pin 4 and the same result - far below 5V. we checked other pins using the blink sketch and the results were the same between the two boards, which are both diecimilias, by the way..
we never plugged in the shield to my board..
something we didn't try was using another meter, but i doubt that would yield a different result, i'm just throwing differences out there.
my tests were run using USB power, while soco's may have been on another power supply... though, i can't recall if it was the board or the shield using it's own power source...
if i find time this evening, i'll check again using my own meter and board again... it's really odd indeed..
my first thought was that some register in the ATMEL needs to be set, but my knowledge is fairly limited when it comes to the AVR, i just use arduino...