#define A 0 #define B 1 #define C 3 #define D 4 #define PIN_CONFIG 0 #define PIN_STATE 1 #define LED_COUNT 13 int matrix[LED_COUNT][2][4] = { // PIN_CONFIG PIN_STATE // A B C D A B C D { { INPUT, INPUT, INPUT, INPUT }, { 0, 0, 0, 0 } }, // 0 { { OUTPUT, OUTPUT, INPUT, INPUT }, { 1, 0, 0, 0 } }, // AB 1 { { OUTPUT, OUTPUT, INPUT, INPUT }, { 0, 1, 0, 0 } }, // BA 2 { { INPUT, OUTPUT, OUTPUT, INPUT }, { 0, 1, 0, 0 } }, // BC 3 { { INPUT, OUTPUT, OUTPUT, INPUT }, { 0, 0, 1, 0 } }, // CB 4 { { OUTPUT, INPUT, OUTPUT, INPUT }, { 1, 0, 0, 0 } }, // AC 5 { { OUTPUT, INPUT, OUTPUT, INPUT }, { 0, 0, 1, 0 } }, // CA 6 { { OUTPUT, INPUT, INPUT, OUTPUT }, { 1, 0, 0, 0 } }, // AD 7 { { OUTPUT, INPUT, INPUT, OUTPUT }, { 0, 0, 0, 1 } }, // DA 8 { { INPUT, OUTPUT, INPUT, OUTPUT }, { 0, 1, 0, 0 } }, // BD 9 { { INPUT, OUTPUT, INPUT, OUTPUT }, { 0, 0, 0, 1 } }, // DB 10 { { INPUT, INPUT, OUTPUT, OUTPUT }, { 0, 0, 1, 0 } }, // CD 11 { { INPUT, INPUT, OUTPUT, OUTPUT }, { 0, 0, 0, 1 } } // DC 12 }; void turnOn( int led ) { pinMode( A, matrix[led][PIN_CONFIG][0] ); pinMode( B, matrix[led][PIN_CONFIG][1] ); pinMode( C, matrix[led][PIN_CONFIG][2] ); pinMode( D, matrix[led][PIN_CONFIG][3] ); digitalWrite( A, matrix[led][PIN_STATE][0] ); digitalWrite( B, matrix[led][PIN_STATE][1] ); digitalWrite( C, matrix[led][PIN_STATE][2] ); digitalWrite( D, matrix[led][PIN_STATE][3] ); } void setup(){ } void izq(){ for(int i=1;i<12;i++){ turnOn(i); delay(50); } for(int i=0;i<5;i++){ turnOn(12); delay(100); turnOn(0); delay(100); } } void der(){ for(int i=12;i>1;i--){ turnOn(i); delay(50); } for(int i=0;i<5;i++){ turnOn(1); delay(100); turnOn(0); delay(100); } } void alto(){ for(int x=0;x<400;x++){ for(int i=1;i<12;i++){ turnOn(i); } } turnOn(0); delay(250); } void loop() { int pos = (analogRead(1)*5/1023); if (pos ==0){ izq(); } else if (pos ==5){ der(); } else { alto(); } }