diff options
-rw-r--r-- | software/animation.ino | 2 | ||||
-rw-r--r-- | software/scan.ino | 47 |
2 files changed, 34 insertions, 15 deletions
diff --git a/software/animation.ino b/software/animation.ino index 1893abe..71ad74b 100644 --- a/software/animation.ino +++ b/software/animation.ino @@ -23,8 +23,6 @@ void fill_plane(unsigned int direction, unsigned int offset) { index += (i / 4) * weights[(direction + 1) % 3]; index += (i % 4) * weights[(direction + 2) % 3]; - Serial.print("xyz"[direction]); - led_state[led_map[index]] = 1; } } diff --git a/software/scan.ino b/software/scan.ino index ef78b42..100f85d 100644 --- a/software/scan.ino +++ b/software/scan.ino @@ -22,7 +22,7 @@ unsigned char get_state_row(unsigned char row, unsigned char direction) { } void scan() { - // optimize_scan(); + optimize_scan(); if (scan_direction == SCAN_HOR) { shift_state[0] = 0x00 ^ (1 << scan_index); @@ -49,26 +49,47 @@ void optimize_scan() { // calculate empty rows/columns for(unsigned char direction = 0; direction < 2; direction++) { - for(unsigned char row; row < 8; row++) { - hv_empty[direction][row] = get_state_row(row, direction) == 0; + for(unsigned char row = 0; row < 8; row++) { + hv_empty[direction][row] = get_state_row(direction == SCAN_HOR ? row : 7 - row, direction) > 0; hv_emptyc[direction] += hv_empty[direction][row]; } } - // print_led_state(); - // delay(20); - - Serial.print("[ "); - for(int i = 0; i < 8; i++) { - Serial.print((unsigned int) hv_empty[0][i], DEC); - if(i != 7) Serial.print(", "); + // garbage debug code (delete if worky) + /* Serial.print("\r\n"); + Serial.print("\r\n"); + Serial.print("\r\n"); + for(int row = -1; row < 8; row++) { + if (row == -1) { + for(int i = 0; i < 8; i++) { + Serial.print(hv_empty[1][i], DEC); + Serial.print(" "); + } + Serial.print("\r\n"); + continue; + } + for(int col = 0; col < 9; col++) { + if (col == 8) { + Serial.print(hv_empty[0][row], DEC); + Serial.print(" "); + continue; + } + Serial.print(led_state[row * 8 + col], DEC); + Serial.print(" "); + } + Serial.print("\n\r"); } - Serial.print(" ] "); + Serial.print("\r\n"); + Serial.print(hv_emptyc[0], DEC); + Serial.print(" "); + Serial.print(hv_emptyc[1], DEC); + Serial.print("\r\n"); + delay(80); */ - optimal_direction = hv_emptyc[0] > hv_emptyc[1] ? 0 : 1; + optimal_direction = hv_emptyc[0] > hv_emptyc[1] ? 1 : 0; scan_direction = optimal_direction; - memcpy(&scan_order, &hv_emptyc[optimal_direction], sizeof(scan_order)); + memcpy(&scan_order, &hv_empty[optimal_direction], sizeof(scan_order)); return; } |