Changing the delay to 5000 does something quite interesting. For 1, the first bit blinks 5 times. For 2, the second bit blinks 5 times. For 3, the second bit blinks then the first bit blinks (repeating this 5 times); this pattern continues for the rest of the count.
They're blinking in pulses just as short as before but it's as if the delay is telling it to blink once every 1000ms.
JediMasterAubie:
Changing the delay to 5000 does something quite interesting. For 1, the first bit blinks 5 times.
What value resistor are you using on the LED?
Is that the correct code you posted? (Please wrap it with code tags and run Tools -> Auto Format before posting).
I can't tell for sure, but your GND connections all line up to the same row, right?
That's very strange.
It could be a low voltage, or watchdog timer, but then the result should not be like this.
So begin with something even more simpler: A blinking led.
Would this result in a fast blinking led.
If not, go for something even more simpler: just turn on some leds and see if they stay on.
Are you sure that the code is actually what you test. Or do you use an analogWrite() or tone() function that uses outputs. I checked the video, and every second something happens, but sometimes there are small delays between the leds within that second. That is almost impossible.
void loop()
{
for ( int i = startNum; i < endNum + 1; i++ )
{
for ( int j = LED0; j < LED4 + 1; j++ )
{
// Read our bit from the number (0 - 15 ) and see if the bit (0 - 3)
// is on or off
//
digitalWrite( j, bitRead( i, j - pinShift ) );
JediMasterAubie:
I've actually had that exact suspicion. So I bought a second Uno today and it's behaving exactly the same as it did on the first.
No kidding. Yet sketches upload OK. How are the Unos being powered?
I'd go back to the absolute basic: Disconnect everything except the USB cable. Upload the blink sketch (File > Examples > Basics > Blink). Should blink the onboard LED, on for 1 sec, off for 1 sec. Is that what happens?
Powered by the USB. Blink seems to be working just fine. The onboard LED blinks exactly as it should; and is responding correctly to alterations to the delay
There is a minor issue with the code, but it is not causing the issue here, actually it's a case where two wrongs make a right.
pow() returns a float. Floats being inexact, pow(2, numBits) must be returning 31.999 or some such, and therefore endNum ends up being 31, not 32 as I might assume at first.
But in the first for loop, this is compensated for, with i < endNum + 1. So as written, the code works exactly as intended. However, I'd do this instead:
#define LED0 7
#define LED1 8
#define LED2 9
#define LED3 10
#define LED4 11
int pinShift = 7;
int numBits = 5;
int startNum = 0;
int endNum = 1 << numBits;
void setup() {
Serial.println(endNum, DEC);
pinMode( LED0, OUTPUT );
pinMode( LED1, OUTPUT );
pinMode( LED2, OUTPUT );
pinMode( LED3, OUTPUT );
pinMode( LED4, OUTPUT );
}
void loop()
{
for ( int i = startNum; i < endNum; i++ )
{
for ( int j = LED0; j < LED4 + 1; j++ )
{
// Read our bit from the number (0 - 15 ) and see if the bit (0 - 3)
// is on or off
//
digitalWrite( j, bitRead( i, j - pinShift ) );
}
delay( 500 );
}
}
JediMasterAubie:
Powered by the USB. Blink seems to be working just fine. The onboard LED blinks exactly as it should; and is responding correctly to alterations to the delay
Well I'm about ready to call Mulder and Scully. Someone didn't slip you some of those LEDs with the built-in blinker did they?
Try the sketch below. Start with no LEDs connected to the board, then add your LEDs one at a time as before.
[quote author=Jack Christensen link=topic=102425.msg768340#msg768340 date=1335055772]
Well I'm about ready to call Mulder and Scully. Someone didn't slip you some of those LEDs with the built-in blinker did they? ;)[/quote]
Huh. So... uh.. .what happens when one of these LEDs are connected directly to 5V and GND (through the resistor)?
Jack, it appears to behave exactly as you said it would. started with them all unplugged and added em all one by one and they're all blinking in unison