aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--software/effects.h6
-rw-r--r--software/effects.ino14
-rw-r--r--software/scan.ino23
-rw-r--r--software/shift.h4
-rw-r--r--software/shift.ino12
-rw-r--r--software/software.ino4
-rw-r--r--software/util.h7
-rw-r--r--software/util.ino18
8 files changed, 59 insertions, 29 deletions
diff --git a/software/effects.h b/software/effects.h
index 04a878a..cef66f2 100644
--- a/software/effects.h
+++ b/software/effects.h
@@ -1,10 +1,10 @@
#pragma once
-// configuratie opties voor de 'diavoorstelling' van de effecten
-#define SLIDESHOW_SIZE (int) 1
+// slideshow config
+#define SLIDESHOW_SIZE (int) 2
#define SLIDESHOW_DURATION (int) 5e3
-// definition of done voor sprint 3
+// definition of done sprint 3
void fx_roundabout (unsigned long relative_time, bool (*leds)[64]);
void fx_wipexyz (unsigned long relative_time, bool (*leds)[64]);
void fx_rainfall (unsigned long relative_time, bool (*leds)[64]);
diff --git a/software/effects.ino b/software/effects.ino
index 0600095..02a56e9 100644
--- a/software/effects.ino
+++ b/software/effects.ino
@@ -1,11 +1,23 @@
+#include "software.h"
#include "effects.h"
void fx_roundabout (unsigned long relative_time, bool (*leds)[64]) {
+ unsigned long segment_time = SLIDESHOW_DURATION / 64;
+ memset(led_state, 0, sizeof(led_state));
+ led_state[(relative_time / segment_time) % 64] = 1;
+
+ return;
+}
+
+void fx_wipexyz (unsigned long relative_time, bool (*leds)[64]) {
+ bool flip_state = (relative_time % 1000) > 500;
+ for(int i = 0; i < 64; i++) led_state[i] = i % 2 == flip_state;
+
return;
}
void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] ) = {
fx_roundabout,
-// fx_wipexyz,
+ fx_wipexyz,
// fx_rainfall
};
diff --git a/software/scan.ino b/software/scan.ino
index 5500f98..8711502 100644
--- a/software/scan.ino
+++ b/software/scan.ino
@@ -2,27 +2,25 @@
#include "shift.h"
#include "software.h"
+// 0 = horizontal (top-bottom), 1 = vertical (left-right)
unsigned char scan_direction = 0;
unsigned char scan_index = 0;
-unsigned char scan_order[8] = {1};
+unsigned char scan_order[8] = {1, 1, 1, 1, 1, 1, 1, 1};
unsigned char get_state_row(unsigned char row, unsigned char direction) {
- unsigned char return_value;
+ unsigned char return_value = 0;
for (int i = 0; i < 8; i++)
- return_value = return_value | ( led_state[ direction == SCAN_HOR ?
- (i + row * 8) : (row + i * 8) ] << (7 - i));
+ return_value = return_value | ( led_state[
+ direction == SCAN_HOR ? (i + row * 8) : (row + i * 8) ] << (7 - i));
return return_value;
}
void scan() {
- unsigned char scan_row = 0xff ^ (1 << scan_index);
+ shift_state[0] = 0xff ^ (1 << scan_index);
+ shift_state[1] = get_state_row(scan_index, scan_direction);
- shift_state[scan_direction] = scan_row;
- shift_state[!scan_direction] = get_state_row(scan_index, scan_direction);
-
- // update physical state of shift register
update_shift_state();
// go to next row/column
@@ -32,12 +30,10 @@ void scan() {
break;
}
}
-
void optimize_scan() {
- unsigned char optimal_direction = 0,
+ unsigned char optimal_direction,
hv_emptyc[2] = {0},
- hv_empty[2][8] = {0},
- optimal_scan_index = 0;
+ hv_empty[2][8] = {0};
// calculate empty rows/columns
for(unsigned char direction = 0; direction < 2; direction++) {
@@ -50,6 +46,7 @@ void optimize_scan() {
}
optimal_direction = hv_emptyc[0] > hv_emptyc[1] ? 0 : 1;
+ scan_direction = optimal_direction;
memcpy(&scan_order, &hv_emptyc[optimal_direction], sizeof(scan_order));
return;
diff --git a/software/shift.h b/software/shift.h
index 61b0557..2b4f7fd 100644
--- a/software/shift.h
+++ b/software/shift.h
@@ -4,8 +4,8 @@
#define SR_COL 1
extern unsigned char shift_state[2];
-/** @brief shift shift_state naar de shift registers */
+/** @brief update physical state of shift registers with shift_state */
void update_shift_state();
-/** @brief direct data naar de shift registers sturen */
+/** @brief directly push data to the serial in of the shift registers */
void shift(unsigned char data);
diff --git a/software/shift.ino b/software/shift.ino
index b27795a..20c1123 100644
--- a/software/shift.ino
+++ b/software/shift.ino
@@ -1,7 +1,10 @@
#include "shift.h"
#include "consts.h"
+#ifdef DEBUG
+#include "util.h"
+#endif
-unsigned char shift_state[2] = {0};
+unsigned char shift_state[2];
void update_shift_state() {
for(int i = 0; i < 2; i++)
@@ -9,18 +12,13 @@ void update_shift_state() {
}
void shift(unsigned char data) {
- #ifdef DEBUG
- Serial.print("Sending data to shift register: ");
- Serial.println(data, BIN);
- #endif
-
// pull down latch
digitalWrite(PINOUT_LCK, LOW);
for(int i = 0; i < 8; i++) {
bool bit = (data & 1 << i) > 0;
- // schrijf bit en pulse serial clock
+ // write bit and pulse serial clock
digitalWrite(PINOUT_SER, bit);
digitalWrite(PINOUT_SCK, HIGH);
delayMicroseconds(CONFIG_SRSER_DELAY);
diff --git a/software/software.ino b/software/software.ino
index 323a79b..5bf0ac3 100644
--- a/software/software.ino
+++ b/software/software.ino
@@ -3,10 +3,8 @@
#include "effects.h"
#include "scan.h"
-unsigned long frame_time_millis = 0;
-
+unsigned long frame_time_millis;
bool led_state[64];
-
bool scan_enable = true;
void setup() {
diff --git a/software/util.h b/software/util.h
new file mode 100644
index 0000000..077fd68
--- /dev/null
+++ b/software/util.h
@@ -0,0 +1,7 @@
+#pragma once
+#ifdef DEBUG
+
+void print_binary_number(unsigned char data);
+void print_led_state();
+
+#endif
diff --git a/software/util.ino b/software/util.ino
new file mode 100644
index 0000000..ef680c4
--- /dev/null
+++ b/software/util.ino
@@ -0,0 +1,18 @@
+#ifdef DEBUG
+#include "software.h"
+
+void print_binary_number(unsigned char data) {
+ for(int i = 7; i >= 0; i--) Serial.print((data & (1 << i)) > 0, DEC);
+}
+
+void print_led_state() {
+ for(int row = 0; row < 8; row++) {
+ for(int col = 0; col < 8; col++) {
+ Serial.print(led_state[row * 8 + col], DEC);
+ Serial.print(" ");
+ }
+ Serial.print("\n\r");
+ }
+}
+
+#endif