Created
December 6, 2018 22:59
-
-
Save davedarko/c7194af7392a0230456de9129d87f908 to your computer and use it in GitHub Desktop.
tiny_LS_cp_short_buffer_2
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 = 4; // 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= -4; i<24; i++) | |
{ | |
for (int k=0;k<shifter_factor;k++) | |
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 | |
} | |
} | |
} | |
} | |
} | |
charlie(-1); | |
toggle = !toggle; | |
if (toggle) delay(1000); | |
} | |
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