diff options
-rw-r--r-- | software/animation.h | 5 | ||||
-rw-r--r-- | software/animation.ino | 23 | ||||
-rw-r--r-- | software/consts.h | 7 | ||||
-rw-r--r-- | software/effects.ino | 29 | ||||
-rw-r--r-- | software/scan.ino | 21 | ||||
-rw-r--r-- | software/software.h | 1 | ||||
-rw-r--r-- | software/software.ino | 9 | ||||
-rw-r--r-- | software/util.ino | 3 |
8 files changed, 53 insertions, 45 deletions
diff --git a/software/animation.h b/software/animation.h index aba955f..e66dad4 100644 --- a/software/animation.h +++ b/software/animation.h @@ -3,7 +3,10 @@ #include "consts.h" /** @brief round time to nearest frame */ -unsigned long clamp_time(unsigned long unclamped_time); +unsigned long clamp_time(unsigned long unclamped_time, double framerate); + +/** @brief get frame */ +unsigned long get_frame(unsigned long unclamped_time, double framerate); /** @brief 'zigzag' value between 0 and `size - 1`, like modulo (`%`) operator */ unsigned int zigzag(unsigned int size, int index); diff --git a/software/animation.ino b/software/animation.ino index edd0c82..dabac0c 100644 --- a/software/animation.ino +++ b/software/animation.ino @@ -1,11 +1,13 @@ -#include "software.h" +#include "animation.h" -unsigned long clamp_time(unsigned long unclamped_time) { +unsigned long clamp_time(unsigned long unclamped_time, double framerate) { + int frame_time_millis = (double) 1000 / framerate; return unclamped_time / frame_time_millis * frame_time_millis; } -unsigned long get_frame(unsigned long relative_time) { - return relative_time / frame_time_millis; +unsigned long get_frame(unsigned long unclamped_time, double framerate) { + int frame_time_millis = (double) 1000 / framerate; + return unclamped_time / frame_time_millis; } unsigned int zigzag(unsigned int size, int index) { @@ -14,19 +16,20 @@ unsigned int zigzag(unsigned int size, int index) { return mod < size - 1 ? mod : zigzag_size - mod; } -void fill_plane(unsigned int direction, unsigned int offset) { +const unsigned int weights[3] = {16, 4, 1}; +void fill_plane(unsigned int direction, unsigned int axis3_offset) { for(int i = 0; i < 16; i++) { unsigned char axis1_offset = i / 4; unsigned char axis2_offset = i % 4; - unsigned int axis1_weight = pow((direction + 1) % 3, 4); - unsigned int axis2_weight = pow((direction - 1) % 3, 4); - unsigned int axis3_weight = pow((direction ) % 3, 4); + unsigned int axis1_weight = weights[(direction + 1) % 3]; + unsigned int axis2_weight = weights[(direction - 1) % 3]; + unsigned int axis3_weight = weights[direction]; led_state[led_map[ - axis1_offset * axis1_weight + + (axis1_offset * axis1_weight + axis2_offset * axis2_weight + - offset * axis3_weight + axis3_offset * axis3_weight) % 64 ]] = 1; } } diff --git a/software/consts.h b/software/consts.h index ed4572d..d78441b 100644 --- a/software/consts.h +++ b/software/consts.h @@ -6,12 +6,9 @@ #define PINOUT_LCK 3 #define PINOUT_NOISE A0 -// animation framerate -#define CONFIG_FRAMERATE 60 - // debug options -#define CONFIG_SERIAL_BAUD 115200 -#define DEBUG +// #define CONFIG_SERIAL_BAUD 115200 +// #define DEBUG /** * @brief map 3D cube coordinates to `led_state` indices diff --git a/software/effects.ino b/software/effects.ino index e8741af..ed4a0b1 100644 --- a/software/effects.ino +++ b/software/effects.ino @@ -2,7 +2,8 @@ #include "effects.h" #include "animation.h" -#define FX_LEN_ROUNDABOUT (unsigned long) 5e3 +// #define FX_LEN_ROUNDABOUT (unsigned long) 5e3 +#define FX_LEN_ROUNDABOUT (unsigned long) 0 void fx_roundabout (unsigned long relative_time) { memset(led_state, 0, sizeof(led_state)); unsigned long tick = relative_time / 300; @@ -26,14 +27,17 @@ void fx_wipexyz (unsigned long relative_time) { unsigned int direction = (tick / 6) % 3; fill_plane(direction, zigzag(4, tick)); + // fill_plane(0, 2); return; } -#define FX_LEN_RAINFALL (unsigned long) 7e3 +// #define FX_LEN_RAINFALL (unsigned long) 7e3 +#define FX_LEN_RAINFALL (unsigned long) 0 +#define FX_FPS_RAINFALL (double) 10 unsigned long last_frame; void fx_rainfall (unsigned long relative_time) { - unsigned long frame = get_frame(relative_time); + unsigned long frame = get_frame(relative_time, FX_FPS_RAINFALL); // only update on new frame if (last_frame != frame) { for (int i = 0x00; i < 0x30; i++) led_state[led_map[i]] = led_state[led_map[i + 0x10]]; @@ -43,10 +47,20 @@ void fx_rainfall (unsigned long relative_time) { return; } +/* #define FX_LEN_TEST_LEDS_IN_ORDER (unsigned long) 10e3 +void test_leds_inorder (unsigned long relative_time) { + memset(led_state, 0, sizeof(led_state)); + unsigned long segment_time = FX_LEN_TEST_LEDS_IN_ORDER / 64; + led_state[(relative_time / segment_time) % 64] = 1; + + return; +} */ + void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time ) = { fx_roundabout, fx_wipexyz, fx_rainfall, + // test_leds_inorder, }; #ifndef SLIDESHOW_DURATION @@ -54,14 +68,7 @@ unsigned long slideshow_lengths[SLIDESHOW_SIZE] = { FX_LEN_ROUNDABOUT, FX_LEN_WIPEXYZ, FX_LEN_RAINFALL, + // FX_LEN_TEST_LEDS_IN_ORDER, }; #endif -/* void test_leds_inorder (unsigned long relative_time)[64]) { - memset(led_state, 0, sizeof(led_state)); - unsigned long segment_time = SLIDESHOW_DURATION / 64; - led_state[(relative_time / segment_time) % 64] = 1; - - return; -} */ - diff --git a/software/scan.ino b/software/scan.ino index b369609..156627b 100644 --- a/software/scan.ino +++ b/software/scan.ino @@ -1,7 +1,10 @@ #include "scan.h" #include "shift.h" #include "software.h" + +#ifdef DEBUG #include "util.h" +#endif // 0 = horizontal (top-bottom), 1 = vertical (left-right) unsigned char scan_direction = 0; @@ -19,7 +22,7 @@ unsigned char get_state_row(unsigned char row, unsigned char direction) { } void scan() { - optimize_scan(); + // optimize_scan(); shift_state[0] = 0x00 ^ (1 << scan_index); shift_state[1] = 0xff ^ get_state_row(scan_index, scan_direction); @@ -33,27 +36,29 @@ void scan() { break; } } + void optimize_scan() { unsigned char optimal_direction, - hv_emptyc[2] = {0}, - hv_empty[2][8] = {0}; + hv_emptyc[2] = {0, 0}, + hv_empty[2][8]; // calculate empty rows/columns for(unsigned char direction = 0; direction < 2; direction++) { for(unsigned char row; row < 8; row++) { - if (get_state_row(row, direction) == 0) { - hv_empty[direction][row] = 1; - hv_emptyc[direction]++; - } + hv_empty[direction][row] = get_state_row(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(", "); } - Serial.print(" ]"); + Serial.print(" ] "); optimal_direction = hv_emptyc[0] > hv_emptyc[1] ? 0 : 1; diff --git a/software/software.h b/software/software.h index 45fe907..b318426 100644 --- a/software/software.h +++ b/software/software.h @@ -1,4 +1,3 @@ #pragma once extern bool led_state[64]; -extern unsigned long frame_time_millis; diff --git a/software/software.ino b/software/software.ino index 4cea2b4..1f03793 100644 --- a/software/software.ino +++ b/software/software.ino @@ -3,7 +3,6 @@ #include "effects.h" #include "scan.h" -unsigned long frame_time_millis; bool led_state[64]; bool scan_enable = true; #ifndef SLIDESHOW_DURATION @@ -27,8 +26,6 @@ void setup() { for(int i = 0; i < SLIDESHOW_SIZE; i++) slideshow_length_total += slideshow_lengths[i]; #endif - - frame_time_millis = (int)((double) 1000 / (double) CONFIG_FRAMERATE); } void loop() { @@ -50,9 +47,9 @@ void loop() { } #endif - #ifdef DEBUG - print_ani_debug(slide_index, slide_time); - #endif + // #ifdef DEBUG + // print_ani_debug(slide_index, slide_time); + // #endif slideshow_effects[slide_index](slide_time); if (scan_enable) scan(); diff --git a/software/util.ino b/software/util.ino index e399c3e..6766d49 100644 --- a/software/util.ino +++ b/software/util.ino @@ -1,5 +1,4 @@ #ifdef DEBUG -#include "software.h" #include "animation.h" void print_binary_number(unsigned char data) { @@ -29,8 +28,6 @@ void print_ani_debug(unsigned int effect_index, unsigned long relative_time) { print_padded_number(relative_time / 1000, " ", 2); Serial.print(","); print_padded_number(relative_time % 1000, "0", 2); - Serial.print(" frame "); - print_padded_number(get_frame(relative_time), " ", 2); Serial.print("\r\n"); } |