Need Help with LED Binary Counter

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.

Should I have anything wired differently? I posted a link to my schematic, with pin numbers, in the first post.

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? :wink:

Try the sketch below. Start with no LEDs connected to the board, then add your LEDs one at a time as before.

#define LED0 7
#define LED1 8
#define LED2 9
#define LED3 10
#define LED4 11
#define ledDelay 1000
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=LED0; i<=LED4; i++) {
        digitalWrite(i, HIGH);
        digitalWrite(13, HIGH);
    }
    delay(ledDelay);

    for (int i=LED0; i<=LED4; i++) {
        digitalWrite(i, LOW);
        digitalWrite(13, LOW);
    }
    delay(ledDelay);
}

[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)?

does the sketch need to be modified at all each time I add an LED?

JediMasterAubie:
does the sketch need to be modified at all each time I add an LED?

Nope, it's blinking them all simultaneously, plus the onboard LED. The intent is just to ramp up the load slowly and see what happens.

James' suggestion is a good one, have you tried the LEDs just alone?

James, I hooked it up to the 5v out and the ground (with the resistor & LED in the circuit) and it's not illuminating the LED at all.

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

Don't understand why one wouldn't illuminate directly off the power supply. Wasn't wired backwards by any chance?

Well if they're all blinking in unison, then don't touch anything :wink: just reload the original sketch!

We await with bated breath...

ARGG!!!! No joy. not illuminating the multiple bits in unison

So like the video in your original post?

exactly

And wiring one as shown below does not illuminate it?

led.png

JediMasterAubie:
James, I hooked it up to the 5v out and the ground (with the resistor & LED in the circuit) and it's not illuminating the LED at all.

Then you didn't wire something correctly. This VERY simple test should light the LED.

Two things to try:

  1. Go back to my 5V/Resistor/LED/GND circuit. If you can't make one LED directly powered light up, there is a significant problem. Either the LED is backwards or you some bad wires.

  2. Jack's simple sketch but, again, increase the delay from 1000 to 5000. Observe the difference.

Where did you buy the LEDs? Do you have a link?

Jack, I wired it up again for the GND to 5V just to double check and I may have accidentally slipped the wrong pin for the 5v the first time. The LED illuminates but it blinks.

Ha! You do have those LEDs with built-in blinker circuits! You need some plain ones!

Holy crap. I thought you were joking when you said with built in blinker circuits. I've been using LED's for years and I had no idea that such a thing existed, but taking a look back at the package, it sure does.

I like it when things turn out to be that simple.

Thanks for all the help guys!!!!!!!!!!!!