1

I want to implement a function thats call "Walking-zero", this supposed to turn all 7 leds and just put one off, and must follow this pattern {1111111, 0111111, 1011111, 1101111, 1110111, 1111011, 1111101, 1111110} where each 1 represents a Led on and each 0 represents a Led off.

Im using {PB0, PB1, PB2, PB3} as my leds output.

So far ive just been able to implement a "Walking-One", which is the oposite of "Walking-Zero".

this is the code for led_config matrix and ledState()this is the code for playSequence() what that does is to keep leds on.

ive tried this:

void ledState(uint8_t j)
{
    DDRB &= ~((1<<PB0) | (1<<PB1) | (1<<PB2) | (1<<PB3));
    
    for(uint8_t i = 0; i<7; i++)
    {
                if( i == j)continue; //
        DDRB |= (1<<led_config[i][0] | (1<<led_config[i][1]));
        PORTB |= (1<<led_config[i][0]);
        PORTB &= ~(1<<led_config[i][1]);
    }
}

what i tried to do was that if j where equals i, that particular led wont turn on, but the rest should, at least thats what i think, honestly im stuck, any help would be appreciate.

9
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Oct 11, 2023 at 0:58
  • 4
    Why do you configure data direction register on each iteration? It's enough to configure output pins once at startup. Please do not upload images of code/data/errors.. Better upload image with your circuit diagram. Are your LEDs connected as counter-parallel pairs? In this case you can't light two LEDs in a pair simultaneously. You only can get illusion of simultaneous light by fast switching polarity. Commented Oct 11, 2023 at 3:15
  • Do you drive the LEDs active high or active low? Commented Oct 11, 2023 at 6:37
  • 1
    Welcome to StackOverflow! Please take the tour to learn how this site works, and read "How to Ask". Then come back and edit your question, providing a minimal reproducible example formatted as source. Please add the schematic of the charlie-plexed LEDs, too, and a link to its explanation, as this method is rarely known. -- Your simplest approach would be a separate timer-controlled routine that outputs a bit image of the LEDs' states. Then change the content of this bit image to your liking. Commented Oct 11, 2023 at 9:58
  • 1
    With charlie-plexing it is possible to statically switch on a single LED, but it is not possible to statically switch on all but one LEDs. Commented Oct 11, 2023 at 10:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.