Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------
- //
- // Charlieplexing Demo
- //
- // Learnelectronics
- // Aug, 23, 2019
- //
- // www.youtube.com/c/learnelectronics
- // email: [email protected]
- //
- //---------------------------------------------
- #define A 8 // We call pin #8 A
- #define B 9 // " " " #9 B
- #define C 10 // " " " #10 C
- #define D 11 // " " " #11 D
- #define PIN_CONFIG 0 // Setup our Boolean config for the 4 pins
- #define PIN_STATE 1 // Setup our Boolean state for the 4 pins
- #define LED_Num 12 // How many LEDs are we using
- // Now we have to create a matrix for the pins so we know which of the 3 states they are in
- int matrix[LED_Num][2][4] = {
- // PIN_CONFIG PIN_STATE
- // A B C D A B C D
- { { OUTPUT, OUTPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW } },
- { { OUTPUT, OUTPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW } },
- { { INPUT, OUTPUT, OUTPUT, INPUT }, { LOW, HIGH, LOW, LOW } },
- { { INPUT, OUTPUT, OUTPUT, INPUT }, { LOW, LOW, HIGH, LOW } },
- { { OUTPUT, INPUT, OUTPUT, INPUT }, { HIGH, LOW, LOW, LOW } },
- { { OUTPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, HIGH, LOW } },
- { { OUTPUT, INPUT, INPUT, OUTPUT }, { HIGH, LOW, LOW, LOW } },
- { { OUTPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, HIGH } },
- { { INPUT, OUTPUT, INPUT, OUTPUT }, { LOW, HIGH, LOW, LOW } },
- { { INPUT, OUTPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, HIGH } },
- { { INPUT, INPUT, OUTPUT, OUTPUT }, { LOW, LOW, HIGH, LOW } },
- { { INPUT, INPUT, OUTPUT, OUTPUT }, { LOW, LOW, LOW, HIGH } }
- };
- //Here we turn the LED on by changing the pin state and mode
- void lightOn( 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() {}
- //here we just incrementally change the number of the LED to beturned on.
- void loop() {
- for( int l = 0; l < LED_Num; l++ ) {
- lightOn( l );
- delay( 5000 / LED_Num );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment