aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-11-24 22:29:50 +0100
committerlonkaars <loek@pipeframe.xyz>2021-11-24 22:29:50 +0100
commitda48b3b203c9bda793cd0deed9dbd05db813d3ce (patch)
tree27d9a66155ebb7e6e077afec37c6ef78d10b60f0
parent15f3bd72a5ee2429616c3a09c349679face715eb (diff)
software
-rw-r--r--16x16/16x16.ino54
-rw-r--r--example/example.ino7
-rw-r--r--software/animation.c0
-rw-r--r--software/animation.h3
-rw-r--r--software/animation.ino5
-rw-r--r--software/consts.h2
-rw-r--r--software/effects.c0
-rw-r--r--software/effects.h13
-rw-r--r--software/effects.ino11
-rw-r--r--software/notes.txt2
-rw-r--r--software/scan.h13
-rw-r--r--software/scan.ino57
-rw-r--r--software/shift.h11
-rw-r--r--software/shift.ino32
-rw-r--r--software/software.h4
-rw-r--r--software/software.ino51
16 files changed, 214 insertions, 51 deletions
diff --git a/16x16/16x16.ino b/16x16/16x16.ino
new file mode 100644
index 0000000..226e4db
--- /dev/null
+++ b/16x16/16x16.ino
@@ -0,0 +1,54 @@
+#define PINOUT_SER 2
+#define PINOUT_SCK 3
+#define PINOUT_LCK 4
+
+bool leds[16];
+
+void animate() {
+ unsigned long t_offset = millis() % (unsigned long)15e3;
+ if(0e3 < t_offset && t_offset < 4e3) {
+ bool flip_state = (t_offset % 1000) > 500;
+ for(int i = 0; i < 16; i++) leds[i] = (i % 2 == flip_state) ^ (i / 4 % 2 == 0) > 0;
+ }
+ else if(4e3 < t_offset && t_offset < 7e3) {
+ bool flip_state = (t_offset % 1000) < 500;
+ for(int i = 0; i < 16; i++) leds[i] = flip_state;
+ }
+ else if(7e3 < t_offset && t_offset < 11e3) {
+ int index = (t_offset - 7e3) / 250;
+ int volgorde[16] = {0, 1, 2, 3, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12};
+ leds[volgorde[(index - 1) % 16]] = 0;
+ leds[volgorde[index % 16]] = 1;
+ }
+ else if(11e3 < t_offset && t_offset < 15e3) {
+ int index = (t_offset - 11e3) / 250;
+ int volgorde[16] = {0, 1, 2, 3, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12};
+ memset(&leds, 0, sizeof(int) * 16);
+ leds[volgorde[index % 16]] = 1;
+ leds[volgorde[15 - index]] = 1;
+ }
+}
+
+void setup() {
+ pinMode(PINOUT_LCK, OUTPUT);
+ pinMode(PINOUT_SCK, OUTPUT);
+ pinMode(PINOUT_SER, OUTPUT);
+ Serial.begin(115200);
+}
+
+void loop() {
+ animate();
+ for (int row = 0; row < 4; row++) {
+ unsigned char serdata = 0xff ^ (1 << (row + 4));
+
+ serdata = (serdata & 0b11110000) |
+ leds[row * 4 + 0] << 3 |
+ leds[row * 4 + 1] << 2 |
+ leds[row * 4 + 2] << 1 |
+ leds[row * 4 + 3] << 0;
+
+ digitalWrite(PINOUT_LCK, LOW);
+ shiftOut(PINOUT_SER, PINOUT_SCK, LSBFIRST, serdata);
+ digitalWrite(PINOUT_LCK, HIGH);
+ }
+}
diff --git a/example/example.ino b/example/example.ino
index 28012c0..a4af127 100644
--- a/example/example.ino
+++ b/example/example.ino
@@ -1,11 +1,8 @@
#define SERIAL_DELAY 3
-// groen
-#define SERIAL_CLK 4
-// geel
+#define SERIAL_CLK 3
#define SERIAL_INP 2
-// blauw
-#define LATCH_CLK 3
+#define LATCH_CLK 4
void setup() {
pinMode(SERIAL_CLK, OUTPUT);
diff --git a/software/animation.c b/software/animation.c
deleted file mode 100644
index e69de29..0000000
--- a/software/animation.c
+++ /dev/null
diff --git a/software/animation.h b/software/animation.h
index fce7081..2626291 100644
--- a/software/animation.h
+++ b/software/animation.h
@@ -2,5 +2,4 @@
#include "consts.h"
-unsigned long clamp_time(unsigned long unclamped_time) {
-}
+unsigned long clamp_time(unsigned long unclamped_time);
diff --git a/software/animation.ino b/software/animation.ino
new file mode 100644
index 0000000..547caaa
--- /dev/null
+++ b/software/animation.ino
@@ -0,0 +1,5 @@
+#include "software.h"
+
+unsigned long clamp_time(unsigned long unclamped_time) {
+ return unclamped_time / frame_time_millis * frame_time_millis;
+}
diff --git a/software/consts.h b/software/consts.h
index b9ddb73..4c577e1 100644
--- a/software/consts.h
+++ b/software/consts.h
@@ -10,4 +10,4 @@
#define CONFIG_SRSER_DELAY 20
#define CONFIG_SERIAL_BAUD 115200
-//#define DEBUG
+// #define DEBUG
diff --git a/software/effects.c b/software/effects.c
deleted file mode 100644
index e69de29..0000000
--- a/software/effects.c
+++ /dev/null
diff --git a/software/effects.h b/software/effects.h
index e69de29..04a878a 100644
--- a/software/effects.h
+++ b/software/effects.h
@@ -0,0 +1,13 @@
+#pragma once
+
+// configuratie opties voor de 'diavoorstelling' van de effecten
+#define SLIDESHOW_SIZE (int) 1
+#define SLIDESHOW_DURATION (int) 5e3
+
+// definition of done voor 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]);
+
+// evil function pointer array
+extern void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] );
diff --git a/software/effects.ino b/software/effects.ino
new file mode 100644
index 0000000..0600095
--- /dev/null
+++ b/software/effects.ino
@@ -0,0 +1,11 @@
+#include "effects.h"
+
+void fx_roundabout (unsigned long relative_time, bool (*leds)[64]) {
+ return;
+}
+
+void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] ) = {
+ fx_roundabout,
+// fx_wipexyz,
+// fx_rainfall
+};
diff --git a/software/notes.txt b/software/notes.txt
new file mode 100644
index 0000000..1b2580a
--- /dev/null
+++ b/software/notes.txt
@@ -0,0 +1,2 @@
+example [ 0, 1, 1, 0, 1, 0, 0 ]
+result [ 0, 1, 1, 0, 1, 0, 0 ]
diff --git a/software/scan.h b/software/scan.h
new file mode 100644
index 0000000..0c19763
--- /dev/null
+++ b/software/scan.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#define SCAN_HOR 0
+#define SCAN_VER 1
+extern unsigned char scan_direction;
+extern unsigned char scan_index;
+extern unsigned char scan_order[8];
+
+unsigned char get_state_row(unsigned char row, unsigned char direction);
+
+void scan();
+void optimize_scan();
+
diff --git a/software/scan.ino b/software/scan.ino
new file mode 100644
index 0000000..5500f98
--- /dev/null
+++ b/software/scan.ino
@@ -0,0 +1,57 @@
+#include "scan.h"
+#include "shift.h"
+#include "software.h"
+
+unsigned char scan_direction = 0;
+unsigned char scan_index = 0;
+unsigned char scan_order[8] = {1};
+
+unsigned char get_state_row(unsigned char row, unsigned char direction) {
+ unsigned char return_value;
+
+ 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 return_value;
+}
+
+void scan() {
+ unsigned char scan_row = 0xff ^ (1 << scan_index);
+
+ 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
+ for(int i = scan_index + 1; i < (scan_index + 7); i++) {
+ if (scan_order[i % 8] == 0) continue;
+ scan_index = i % 8;
+ break;
+ }
+}
+
+void optimize_scan() {
+ unsigned char optimal_direction = 0,
+ hv_emptyc[2] = {0},
+ hv_empty[2][8] = {0},
+ optimal_scan_index = 0;
+
+ // 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]++;
+ }
+ }
+ }
+
+ optimal_direction = hv_emptyc[0] > hv_emptyc[1] ? 0 : 1;
+ memcpy(&scan_order, &hv_emptyc[optimal_direction], sizeof(scan_order));
+
+ return;
+}
+
diff --git a/software/shift.h b/software/shift.h
new file mode 100644
index 0000000..61b0557
--- /dev/null
+++ b/software/shift.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#define SR_ROW 0
+#define SR_COL 1
+extern unsigned char shift_state[2];
+
+/** @brief shift shift_state naar de shift registers */
+void update_shift_state();
+
+/** @brief direct data naar de shift registers sturen */
+void shift(unsigned char data);
diff --git a/software/shift.ino b/software/shift.ino
new file mode 100644
index 0000000..b27795a
--- /dev/null
+++ b/software/shift.ino
@@ -0,0 +1,32 @@
+#include "shift.h"
+#include "consts.h"
+
+unsigned char shift_state[2] = {0};
+
+void update_shift_state() {
+ for(int i = 0; i < 2; i++)
+ shift(shift_state[i]);
+}
+
+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
+ digitalWrite(PINOUT_SER, bit);
+ digitalWrite(PINOUT_SCK, HIGH);
+ delayMicroseconds(CONFIG_SRSER_DELAY);
+ digitalWrite(PINOUT_SCK, LOW);
+ }
+
+ // pull up latch
+ digitalWrite(PINOUT_LCK, HIGH);
+}
diff --git a/software/software.h b/software/software.h
new file mode 100644
index 0000000..45fe907
--- /dev/null
+++ b/software/software.h
@@ -0,0 +1,4 @@
+#pragma once
+
+extern bool led_state[64];
+extern unsigned long frame_time_millis;
diff --git a/software/software.ino b/software/software.ino
index 8c454ac..323a79b 100644
--- a/software/software.ino
+++ b/software/software.ino
@@ -1,30 +1,13 @@
+#include "software.h"
#include "consts.h"
+#include "effects.h"
+#include "scan.h"
-extern unsigned long frame_time_millis;
-bool led_state[64];
-
-void shift(unsigned char data) {
- #ifdef DEBUG
- Serial.print("Sending data to shift register: ");
- Serial.println(data, BIN);
- #endif
+unsigned long frame_time_millis = 0;
- // pull down latch register
- digitalWrite(PINOUT_LCK, LOW);
-
- for(int i = 0; i < 8; i++) {
- bool bit = data & 1 << i > 0;
+bool led_state[64];
- // schrijf bit en pulse serial clock
- digitalWrite(PINOUT_SER, bit);
- digitalWrite(PINOUT_SCK, HIGH);
- delayMicroseconds(CONFIG_SRSER_DELAY);
- digitalWrite(PINOUT_SCK, LOW);
- }
-
- // pull up latch register
- digitalWrite(PINOUT_LCK, HIGH);
-}
+bool scan_enable = true;
void setup() {
pinMode(PINOUT_SER, OUTPUT);
@@ -38,26 +21,6 @@ void setup() {
frame_time_millis = 1000 / CONFIG_FRAMERATE * CONFIG_FRAMERATE;
}
-void test_effect1(unsigned long relative_time, bool (*leds)[64]) {
- return;
-}
-void test_effect2(unsigned long relative_time, bool (*leds)[64]) {
- return;
-}
-void test_effect3(unsigned long relative_time, bool (*leds)[64]) {
- return;
-}
-
-
-#define SLIDESHOW_SIZE ( (int) 3 )
-#define SLIDESHOW_DURATION ( (int) 5e3 )
-// evil function pointer array
-void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] ) = {
- test_effect1,
- test_effect2,
- test_effect3
-};
-
void loop() {
unsigned long current_time = millis();
@@ -65,4 +28,6 @@ void loop() {
unsigned int slide_index = (current_time / SLIDESHOW_DURATION) % SLIDESHOW_SIZE;
slideshow_effects[slide_index](slide_time, &led_state);
+
+ if (scan_enable) scan();
}