# Arduino brute force LEDs.

Okay, so I have 12 Leds and I want to make my arduino turn them on in every 2^12 possible combinations of on and off. I have a python program that can print every combination of a given number of digits, each being either a 1 or a 0, but I have no idea how to transfer this to an arduino, as the python program uses itertools and I don't know how to transfer that to C. Does anyone know of an arduino library for this application, or a method I can use to do this?
I know some C, enough to write a basic program on an arduino, but not much.
I have an arduino nano and an UNO.
This is the python program:

``````import itertools
stuff = ["1","0"]
Length = int(input("length --> "))
res = itertools.product(stuff, repeat=(Length))
for i in res:
attempt = (''.join(i))
print(attempt)
``````

The purpose of this code is to print all of the possible combinations of a password containing "1"s and "0"s. So in an arduino, instead of printing the combinations with serial or whatever, it changes the twelve lights to match the combinations.
So if the first code is "000000000000" the lights would all be off.
Then the next one would be "000000000001" and the lights would all be off except for the last one.

An Arduino library?

Why?

Perhaps you should think about learning C++ if you want to use the Arduino.

Sorry about that. I'm pretty new to forums. I think I've made it more clear.

The purpose of this code is to print all of the possible combinations of a password containing "1"s and "0"s.

That code is totally irrelevant to what you want to do.

In C all you need to do is to generate a variable that has all the possible combinations of 0 and 1 for your range. Like this:-

``````for(int light = 0; light < 4096; light ++) {
switchLEDs(light);
}
``````

Now all you need to do is to write the switchLEDs function.

This takes in a variable and looks at each bit in that variable in turn and turns on or off the appropriate LED. The LED’s pin number should be kept in an array and used to look up the pin number to use. To determine if a bit is set in a variable use a bit mask. This is simply a variable with only one logic one in it. Use the bitwise AND instruction ( symbol & ) to test the variable. Like this:-

``````void switchLEDs( int lights ){
int mask = 1;
for( int i = 0; i < 4096; i++){
digitalWrite(pins[i], HIGH);
}
else {
digitalWrite(pins[i], LOW);
}
mask = mask << 1; // shift left the mask
}
}
``````

I will leave you to define the pins array and initialize the pins to be outputs and also stop it all going so fast.

12 bits is 4096 combinations, not 1024. Better still 0x1000

Also that switchLEDs code is all awry, try something more like:

``````void setup ()
{
for (byte led = 0 ; led < 12 ; led++)
pinMode (pins [led], OUTPUT) ;
}

void loop ()
{
for (int i = 0 ; i < 0x1000 ; i++)
{
switchLEDs (i) ;
delay (50) ;
}
}

void switchLEDs (int pattern)
{
for (byte led = 0 ; led < 12 ; led++)
digitalWrite (pins [led], (pattern >> led) & 1) ;
}
``````

fourth-decent:
The purpose of this code is to print all of the possible combinations of a password containing "1"s and "0"s. So in an Arduino, instead of printing the combinations with serial or whatever, it changes the twelve lights to match the combinations.

And then what?

Four thousand and ninety six different combinations. What are you going to do with them as they are displayed? 12 bits is 4096 combinations, not 1024. Better still 0x1000

Yes i'll give you that one. Changes edited in post.

Also that switchLEDs code is all awry,

However not that one. Yes your alternative will work but so will my code.