2018-07-06 07:02:01 +00:00
|
|
|
/*
|
|
|
|
* This is a "Library" of sorts, where I have made several (admittedly basic)
|
|
|
|
* functions based off of the original examples provided. Currently these are aimed at
|
|
|
|
* displaying what I'll dub "Pixols", the 2D array that contains the pixels and RGB
|
|
|
|
* values resulting from using the python image converter.
|
|
|
|
*
|
|
|
|
* You can flash this directly to your pixel to see a demonstration of each
|
|
|
|
*
|
|
|
|
* Note that this does not interact with the MPU
|
|
|
|
*/
|
|
|
|
|
2018-07-06 06:05:01 +00:00
|
|
|
#include <Adafruit_GFX.h>
|
|
|
|
#include <Adafruit_DotStarMatrix.h>
|
|
|
|
#include <Adafruit_DotStar.h>
|
|
|
|
#include <ArduinoJson.h>
|
2018-07-06 07:02:01 +00:00
|
|
|
#include "pixols.h"
|
2018-07-06 06:05:01 +00:00
|
|
|
|
|
|
|
#define DATAPIN 19
|
|
|
|
#define CLOCKPIN 18
|
2018-07-25 02:18:09 +00:00
|
|
|
#define BRIGHTNESS 15
|
2018-07-25 02:16:38 +00:00
|
|
|
#define TOTALPXLS 256 // The total number of LEDs
|
|
|
|
|
|
|
|
// This structure stores the state of all of the LEDS
|
|
|
|
// The loop will reset various parts of this, such as the active state
|
|
|
|
// to allow multiple animations to occurr in a row
|
|
|
|
struct PXL {
|
|
|
|
byte id: 1;
|
|
|
|
byte r: 1;
|
|
|
|
byte g: 1;
|
|
|
|
byte b: 1;
|
|
|
|
byte active: 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PXL pixols[TOTALPXLS];
|
2018-07-06 06:05:01 +00:00
|
|
|
|
|
|
|
Adafruit_DotStarMatrix matrix = Adafruit_DotStarMatrix(
|
|
|
|
16, 16, DATAPIN, CLOCKPIN,
|
|
|
|
DS_MATRIX_TOP + DS_MATRIX_LEFT +
|
|
|
|
DS_MATRIX_ROWS + DS_MATRIX_PROGRESSIVE,
|
|
|
|
DOTSTAR_BGR);
|
|
|
|
|
2018-07-25 02:18:09 +00:00
|
|
|
int activePixelCount() {
|
|
|
|
int totalActive = 0;
|
|
|
|
for (int cnt = 0; cnt < TOTALPXLS; cnt++) {
|
|
|
|
if (pixols[cnt].active == true) totalActive++;
|
|
|
|
}
|
|
|
|
return totalActive;
|
|
|
|
}
|
2018-07-06 06:10:25 +00:00
|
|
|
|
2018-07-25 02:18:09 +00:00
|
|
|
// Use this at the beginning of functions that set the active state
|
|
|
|
void resetActiveState() {
|
|
|
|
for (int i = 0; i < TOTALPXLS; i++)
|
|
|
|
pixols[i].active = false;
|
2018-07-06 06:05:01 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 06:07:19 +00:00
|
|
|
/*
|
2018-07-06 07:02:01 +00:00
|
|
|
* showPxl, displays a Pixol to the display with no animation
|
2018-07-06 06:07:19 +00:00
|
|
|
* args:
|
2018-07-25 02:18:09 +00:00
|
|
|
* - pxl[TOTALPXLS][3] - Standard Pixol image
|
2018-07-06 06:07:19 +00:00
|
|
|
* - dlytime - The amount of time (in ms) to keep the image on the display
|
2018-07-25 02:19:05 +00:00
|
|
|
* - color (optional) - Whether or not to set the active pixel's color to its stored value
|
2018-07-06 06:07:19 +00:00
|
|
|
*/
|
2018-07-25 02:19:05 +00:00
|
|
|
void showPxl(int pxl[TOTALPXLS][3], int dlytime, bool color=false) {
|
|
|
|
resetActiveState();
|
|
|
|
|
|
|
|
for (int i=0; i < TOTALPXLS; i++){
|
|
|
|
if (pxl[i][0] != 0 && pxl[i][1] != 0 && pxl[i][2] != 0) {
|
|
|
|
pixols[i].active = true;
|
|
|
|
}
|
2018-07-06 06:07:19 +00:00
|
|
|
|
2018-07-25 02:19:05 +00:00
|
|
|
if (!color) {
|
|
|
|
matrix.setPixelColor(i, pxl[i][0], pxl[i][1], pxl[i][2]);
|
|
|
|
}else {
|
|
|
|
if (pixols[i].active) {
|
|
|
|
matrix.setPixelColor(i, pxl[i][pixols[i].r],
|
|
|
|
pxl[i][pixols[i].g],
|
|
|
|
pxl[i][pixols[i].b]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-07-06 06:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
matrix.show();
|
|
|
|
delay(dlytime);
|
|
|
|
|
|
|
|
matrix.fillScreen(0);
|
|
|
|
matrix.show();
|
|
|
|
}
|
2018-07-06 06:08:21 +00:00
|
|
|
|
|
|
|
// Notification functions
|
|
|
|
|
|
|
|
/*
|
2018-07-06 07:02:01 +00:00
|
|
|
* notifyPopupPxl, draws a Pixol that scrolls into view, and back down
|
2018-07-06 06:08:21 +00:00
|
|
|
* args:
|
2018-07-25 02:18:09 +00:00
|
|
|
* - pxl[TOTALPXLS][3] - Standard Pixol image
|
2018-07-06 06:08:21 +00:00
|
|
|
* - dlytime - The amount of time (in ms) to keep the image on the display
|
|
|
|
*/
|
2018-07-25 02:18:09 +00:00
|
|
|
void notifyPopupPxl(int pxl[TOTALPXLS][3], int dlytime) {
|
2018-07-06 06:08:21 +00:00
|
|
|
for (int j = 15; j >= 0; j--) {
|
2018-07-25 02:18:09 +00:00
|
|
|
for (int i = 0; i < TOTALPXLS; i++) {
|
2018-07-06 06:08:21 +00:00
|
|
|
matrix.setPixelColor(i + (j * 16),
|
2018-07-06 07:02:01 +00:00
|
|
|
pxl[i][0], pxl[i][1], pxl[i][2]);
|
2018-07-06 06:08:21 +00:00
|
|
|
}
|
|
|
|
matrix.show();
|
|
|
|
delay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(dlytime);
|
|
|
|
|
|
|
|
for (int j = 0; j <= 16; j++) {
|
2018-07-25 02:18:09 +00:00
|
|
|
for (int i = 0; i < TOTALPXLS; i++) {
|
|
|
|
matrix.setPixelColor(i + (j * 16),
|
|
|
|
pxl[i][0], pxl[i][1], pxl[i][2]);
|
2018-07-06 06:08:21 +00:00
|
|
|
}
|
|
|
|
matrix.show();
|
|
|
|
delay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(100);
|
|
|
|
}
|
2018-07-06 06:11:43 +00:00
|
|
|
|
|
|
|
/*
|
2018-07-06 07:02:01 +00:00
|
|
|
* notifyScrollPxl, draws a Pixol that scrolls upward into view, and upwards out; Loop this to scroll X times
|
2018-07-06 06:11:43 +00:00
|
|
|
* args:
|
2018-07-25 02:18:09 +00:00
|
|
|
* - pxl[TOTALPXLS][3] - Standard Pixol image
|
2018-07-06 06:11:43 +00:00
|
|
|
* - dlytime - The amount of time (in ms) to keep the image on the display
|
2018-07-06 06:31:46 +00:00
|
|
|
* - loops (optional) - The total amount of times this should loop through
|
2018-07-06 06:11:43 +00:00
|
|
|
*/
|
2018-07-25 02:18:09 +00:00
|
|
|
void notifyScrollPxl(int pxl[TOTALPXLS][3], int dlytime, int loops=0) {
|
2018-07-06 06:11:43 +00:00
|
|
|
for (int x=0; x<=loops; x++) {
|
|
|
|
for (int j = 15; j >= 0; j--) {
|
2018-07-25 02:18:09 +00:00
|
|
|
for (int i = 0; i < TOTALPXLS; i++) {
|
2018-07-06 06:11:43 +00:00
|
|
|
matrix.setPixelColor(i + (j * 16),
|
2018-07-06 07:02:01 +00:00
|
|
|
pxl[i][0], pxl[i][1], pxl[i][2]);
|
2018-07-06 06:11:43 +00:00
|
|
|
}
|
|
|
|
matrix.show();
|
|
|
|
delay(15);
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(dlytime);
|
|
|
|
|
|
|
|
for (int j = 0; j >= -16; j--) {
|
2018-07-25 02:18:09 +00:00
|
|
|
for (int i = 0; i < TOTALPXLS; i++) {
|
2018-07-06 06:11:43 +00:00
|
|
|
matrix.setPixelColor(i + (j * 16),
|
2018-07-06 07:02:01 +00:00
|
|
|
pxl[i][0], pxl[i][1], pxl[i][2]);
|
2018-07-06 06:11:43 +00:00
|
|
|
}
|
|
|
|
matrix.show();
|
|
|
|
delay(15);
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:20:25 +00:00
|
|
|
/*
|
|
|
|
* notifyBlinkPxl, flash a Pixol on screen repeatedly
|
|
|
|
* args:
|
2018-07-25 02:28:58 +00:00
|
|
|
* - pxl[TOTALPXLS][3] - Standard Pixol image, displayed all at once
|
2018-07-25 02:20:25 +00:00
|
|
|
* - dlytime - The amount of time (in ms) to keep the image on the display
|
|
|
|
* - loops (optional) - The total amount of times this should blink
|
|
|
|
* - color (optional) - Whether or not to set the active pixel's color to its stored value
|
|
|
|
*/
|
2018-07-25 02:28:58 +00:00
|
|
|
void notifyBlinkPxl(int pxl[TOTALPXLS][3], int dlytime, int loops=0, bool color=false) {
|
2018-07-25 02:20:25 +00:00
|
|
|
for (int i = 0; i <= loops; i++) {
|
|
|
|
showPxl(pxl, dlytime, color);
|
|
|
|
showPxl(darkness, dlytime, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 06:10:25 +00:00
|
|
|
// "Animation" or picture transition functions
|
|
|
|
|
|
|
|
/*
|
2018-07-06 07:02:01 +00:00
|
|
|
* scanChangePxl, Change from one Pixol to another with a scanline appearence
|
2018-07-06 06:10:25 +00:00
|
|
|
* args:
|
2018-07-25 02:18:09 +00:00
|
|
|
* - src[TOTALPXLS][3] - Standard Pixo-Style icon that we change from, displayed all at once
|
|
|
|
* - dst[TOTALPXLS][3] - Standard Pixo-Style icon that we change to, displayed one pixel at a time
|
2018-07-06 06:10:25 +00:00
|
|
|
* - dlytime - The amount of time (in ms) to keep the image on the display
|
2018-07-06 06:31:46 +00:00
|
|
|
* - anitime - The amount of time (in ms) between drawing each pixel during the transition; the lower this number, the faster the transition
|
2018-07-06 06:10:25 +00:00
|
|
|
*/
|
2018-07-25 02:18:09 +00:00
|
|
|
void scanChangePxl(int src[TOTALPXLS][3], int dst[TOTALPXLS][3], int dlytime, int anitime) {
|
|
|
|
for (int i=0; i<TOTALPXLS; i++){
|
2018-07-06 06:10:25 +00:00
|
|
|
matrix.setPixelColor(i, src[i][0], src[i][1], src[i][2]);
|
|
|
|
}
|
|
|
|
matrix.show();
|
|
|
|
|
|
|
|
delay(dlytime);
|
|
|
|
|
2018-07-25 02:18:09 +00:00
|
|
|
for (int i=0; i<TOTALPXLS; i++){
|
2018-07-06 06:10:25 +00:00
|
|
|
matrix.setPixelColor(i, dst[i][0], dst[i][1], dst[i][2]);
|
|
|
|
matrix.show();
|
|
|
|
delay(anitime);
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(dlytime);
|
2018-07-06 06:05:01 +00:00
|
|
|
}
|
2018-07-06 06:31:46 +00:00
|
|
|
|
|
|
|
/*
|
2018-07-06 07:02:01 +00:00
|
|
|
* randChangePxl, Change from one Pixol to another with a random pixel selection
|
2018-07-06 06:31:46 +00:00
|
|
|
* args:
|
2018-07-25 02:18:09 +00:00
|
|
|
* - src[TOTALPXLS][3] - Standard Pixo-Style icon that we change from, displayed all at once
|
|
|
|
* - dst[TOTALPXLS][3] - Standard Pixo-Style icon that we change to, displayed one pixel at a time
|
2018-07-06 06:31:46 +00:00
|
|
|
* - dlytime - The amount of time (in ms) to keep the image on the display
|
|
|
|
* - anitime - The amount of time (in ms) between drawing each pixel during the transition; the lower this number, the faster the transition
|
|
|
|
*/
|
2018-07-25 02:21:38 +00:00
|
|
|
void randChangePxl(int src[TOTALPXLS][3], int dst[TOTALPXLS][3], int dlytime, int anitime) {
|
|
|
|
resetActiveState();
|
|
|
|
|
|
|
|
// Image that we are animating from
|
|
|
|
for (int i = 0; i < TOTALPXLS; i++){
|
|
|
|
pixols[i].active = false;
|
2018-07-06 06:31:46 +00:00
|
|
|
matrix.setPixelColor(i, src[i][0], src[i][1], src[i][2]);
|
|
|
|
}
|
|
|
|
matrix.show();
|
|
|
|
|
|
|
|
delay(dlytime);
|
2018-07-25 02:21:38 +00:00
|
|
|
|
|
|
|
// Image that we are animating to
|
|
|
|
while (activePixelCount() < TOTALPXLS) {
|
|
|
|
randomSeed(A1);
|
|
|
|
int selected = random(0, TOTALPXLS);
|
|
|
|
|
|
|
|
// Select only pixels that have not already been set
|
|
|
|
if (pixols[selected].active) {
|
|
|
|
while (true) {
|
|
|
|
selected = random(0, TOTALPXLS);
|
|
|
|
if (!pixols[selected].active) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 06:31:46 +00:00
|
|
|
|
2018-07-25 02:21:38 +00:00
|
|
|
pixols[selected].active = true;
|
|
|
|
matrix.setPixelColor(selected, dst[selected][0],
|
|
|
|
dst[selected][1],
|
|
|
|
dst[selected][2]);
|
2018-07-06 06:31:46 +00:00
|
|
|
matrix.show();
|
|
|
|
delay(anitime);
|
2018-07-25 02:21:38 +00:00
|
|
|
|
|
|
|
if (activePixelCount() >= TOTALPXLS) break;
|
2018-07-06 06:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delay(dlytime);
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:23:32 +00:00
|
|
|
void setup(void) {
|
|
|
|
matrix.begin();
|
|
|
|
matrix.setBrightness(BRIGHTNESS);
|
2018-07-06 06:31:46 +00:00
|
|
|
|
2018-07-25 02:23:32 +00:00
|
|
|
// Initialize our pixel structure
|
|
|
|
for (int cnt = 0; cnt < TOTALPXLS; cnt++) {
|
|
|
|
pixols[cnt].active = false;
|
|
|
|
pixols[cnt].id = cnt;
|
|
|
|
}
|
2018-07-06 06:31:46 +00:00
|
|
|
|
2018-07-25 02:23:32 +00:00
|
|
|
// Bootup SH logo
|
|
|
|
showPxl(sh, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
showPxl(twitter, 1000);
|
|
|
|
randChangePxl(twitter, ig, 1000, 20);
|
|
|
|
notifyScrollPxl(upvote, 1000, 2);
|
|
|
|
notifyPopupPxl(glogo, 1000);
|
2018-07-25 02:28:58 +00:00
|
|
|
notifyBlinkPxl(wifi, 1000, 3);
|
|
|
|
|
2018-07-06 06:31:46 +00:00
|
|
|
}
|