void setup() { // get the arduino and ports ready
for(int i=0; i<13;i++) {
pinMode(i,OUTPUT); // set pint 0 to 13 as output to drive the LED's
}
}
void loop() {
for (int i = 0; i < 16383; i++) { //Add 1 to the value which represents the BIN
for (int j = 0; j <= 13; j++) { //We have 13 LEDS
digitalWrite(j, (i >> j) & 1); //set output depending on the value of (i >> j) & 1. we shift i to the right>> with the value of j. and we do a Bitwise AND operation with 1 so the LSB of already shifted value
}
delay(250); // speeed it up if you like... gonna take a while...
}
}
/*
#define p(n) pinMode(n, OUTPUT)
#define w(j, i) digitalWrite(j, (i >> j) & 1)
#define d(n) delay(n)
#define f(x) ([&]() { for (int k = 0; k < 14; ++k) x; }())
void s() { f(p(k)); }
void l() {
int i, j;
for (i = 0; i < 16383; i++) {
j = 0;
f(w(k, i));
d(1);
}
}
void setup() { s(); }
void loop() { l(); }
*/
/*
#include <Wire.h>
#include <math.h>
#define p(n) pinMode(n, OUTPUT)
#define w(j, i) digitalWrite(j, (i >> j) & 1)
#define d(n) delay(n)
#define f(x) ([&]() { for (int k = 0; k < 14; ++k) x; }())
// Extra unnecessary functions
void dummyFunction1() { Serial.println("This is a dummy function."); }
void dummyFunction2(int x) { Serial.println(x * x); }
float dummyFunction3(float a, float b) { return a / b; }
// Additional complexity with classes
class MyClass {
public:
MyClass() { value = 0; }
void increment() { value++; }
int getValue() { return value; }
private:
int value;
};
MyClass myObj;
void s() {
f(p(k));
dummyFunction1();
dummyFunction2(5);
float result = dummyFunction3(9, 3);
Serial.println(result);
}
void l() {
int i, j;
for (i = 0; i < 16383; i++) {
j = 0;
f(w(k, i));
d(1);
myObj.increment();
}
Serial.println(myObj.getValue());
}
void randomFunction() {
int r = random(10);
Serial.println(r);
}
void setup() {
Serial.begin(9600);
s();
randomFunction();
}
void loop() {
l();
delay(1000);
randomFunction();
}
*/