Created
November 20, 2018 15:39
-
-
Save davedarko/06e8c38d0bc12cf603ae853488b9737a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Based on https://github.com/maltesemanTS1/Charlieplexing-the-Arduino | |
http://arduino.cc/en/Tutorial/BitMask | |
*/ | |
int16_t shifter = 0; | |
uint8_t shifter_factor = 8; // also speed influence | |
bool toggle = true; | |
const uint8_t max_leds = 20; | |
uint8_t pwm_value; | |
uint8_t pwm_values[5] = { 127, 63, 32, 15, 1 }; | |
void setup() | |
{ | |
} | |
void loop() { | |
short_buffer_write(); | |
} | |
void short_buffer_write() | |
{ | |
for (int i= -5; i<25; i++) | |
{ | |
for (uint8_t p = 0; p < 127; p++) | |
{ | |
for (int j=0; j<5; j++) | |
{ | |
if ( | |
i+j >= 0 && | |
i+j < 20 | |
) { | |
if (toggle) pwm_value = pwm_values[4-j]; | |
else pwm_value = pwm_values[j]; | |
if (p < pwm_value) | |
{ | |
if (toggle) charlie(i+j); | |
else charlie(max_leds - i + j -1); // -1 to get to zero | |
// delayMicroseconds(10); | |
} | |
} | |
} | |
} | |
} | |
charlie(-1); | |
toggle = !toggle; | |
if (toggle) delay(2000); | |
} | |
void charlie_combo(uint8_t a, uint8_t b) | |
{ | |
// output | |
DDRB |= (1 << a); | |
// output | |
DDRB |= (1 << b); | |
// high | |
PORTB |= (1<<a); | |
// low | |
PORTB &= ~(1<<b); | |
} | |
void charlie (uint8_t var) | |
{ | |
// DDRB |= (0x1F); | |
DDRB &= ~(0x1F); | |
PORTB &= ~(0x1F); | |
switch (var) { | |
case 0: charlie_combo(0, 1); break; | |
case 1: charlie_combo(1, 0); break; | |
case 2: charlie_combo(0, 2); break; | |
case 3: charlie_combo(2, 0); break; | |
case 4: charlie_combo(0, 3); break; | |
case 5: charlie_combo(3, 0); break; | |
case 6: charlie_combo(0, 4); break; | |
case 7: charlie_combo(4, 0); break; | |
case 8: charlie_combo(1, 2); break; | |
case 9: charlie_combo(2, 1); break; | |
case 10: charlie_combo(1, 3); break; | |
case 11: charlie_combo(3, 1); break; | |
case 12: charlie_combo(1, 4); break; | |
case 13: charlie_combo(4, 1); break; | |
case 14: charlie_combo(2, 3); break; | |
case 15: charlie_combo(3, 2); break; | |
case 16: charlie_combo(2, 4); break; | |
case 17: charlie_combo(4, 2); break; | |
case 18: charlie_combo(3, 4); break; | |
case 19: charlie_combo(4, 3); break; | |
default: ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment