2018-12-09 21:43:08 +01:00
|
|
|
// DotStarTest
|
|
|
|
// This example will cycle between showing four pixels as Red, Green, Blue, White
|
|
|
|
// and then showing those pixels as Black.
|
|
|
|
//
|
|
|
|
// There is serial output of the current state so you can confirm and follow along
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <NeoPixelBus.h>
|
2018-12-11 21:06:43 +01:00
|
|
|
#include <NeoPixelBrightnessBus.h>
|
2018-12-11 21:26:09 +01:00
|
|
|
#include "defaults.h"
|
2018-12-09 21:43:08 +01:00
|
|
|
|
2018-12-09 22:03:57 +01:00
|
|
|
RgbColor *c[16];
|
2018-12-11 21:06:43 +01:00
|
|
|
RgbColor black(0);
|
2018-12-09 21:43:08 +01:00
|
|
|
|
2018-12-20 17:45:07 +01:00
|
|
|
const uint16_t PixelCount = 128; // Currently we have a 2x 8x8 matrix connected
|
2018-12-09 21:43:08 +01:00
|
|
|
|
|
|
|
// make sure to set this to the correct pins
|
2018-12-11 21:06:43 +01:00
|
|
|
// SPI Hardware Pins: CLK=GPIO14=Pin12=D5 (orange), MOSI=GPIO13=Pin13=D7 (yellow)
|
2018-12-16 22:04:41 +01:00
|
|
|
//NeoPixelBrightnessBus<DotStarBgrFeature, DotStarSpiMethod> strip(PixelCount);
|
|
|
|
NeoPixelBus<DotStarBgrFeature, DotStarSpiMethod> strip(PixelCount);
|
2018-12-09 21:43:08 +01:00
|
|
|
|
2018-12-11 21:06:43 +01:00
|
|
|
void setup() {
|
2018-12-09 21:43:08 +01:00
|
|
|
Serial.begin(115200);
|
|
|
|
while (!Serial); // wait for serial attach
|
|
|
|
|
|
|
|
Serial.println();
|
2018-12-11 21:30:00 +01:00
|
|
|
Serial.println("Initializing..."); Serial.flush();
|
2018-12-09 21:43:08 +01:00
|
|
|
|
|
|
|
// this resets all the neopixels to an off state
|
|
|
|
strip.Begin();
|
2018-12-16 22:04:41 +01:00
|
|
|
//strip.SetBrightness(brightness);
|
2018-12-09 21:43:08 +01:00
|
|
|
strip.ClearTo(black);
|
|
|
|
strip.Show();
|
|
|
|
|
|
|
|
Serial.println();
|
2018-12-11 21:26:09 +01:00
|
|
|
|
|
|
|
loadColorMap(colorMap);
|
|
|
|
|
2018-12-09 21:43:08 +01:00
|
|
|
Serial.println("Running...");
|
2018-12-09 22:03:57 +01:00
|
|
|
|
2018-12-11 21:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// loading ColorMap into color objects
|
|
|
|
void loadColorMap(uint8_t cmap[]) {
|
2018-12-09 22:03:57 +01:00
|
|
|
for(int n=0; n<16; n++) {
|
2018-12-11 21:26:09 +01:00
|
|
|
c[n] = new RgbColor(cmap[n*3], cmap[n*3+1], cmap[n*3+2]);
|
2018-12-09 22:03:57 +01:00
|
|
|
}
|
2018-12-09 21:43:08 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 21:44:26 +01:00
|
|
|
// play a given sub-animation
|
|
|
|
void playBwAnimation(int animDelay, uint8_t anim[][8]) {
|
|
|
|
|
|
|
|
for(int frame=0; frame<7; frame++) {
|
2018-12-20 17:45:07 +01:00
|
|
|
for(int n=0; n<strip.PixelCount()/16; n++) {
|
2018-12-16 21:44:26 +01:00
|
|
|
for(int i=0; i<8; i++) {
|
2018-12-20 17:45:07 +01:00
|
|
|
if((anim[frame][n])&(1<<i)) {
|
|
|
|
strip.SetPixelColor(i*8+n, RgbColor(brightness));
|
|
|
|
strip.SetPixelColor(i*8+n+64, RgbColor(brightness));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strip.SetPixelColor(i*8+n, RgbColor(0));
|
|
|
|
strip.SetPixelColor(i*8+n+64, RgbColor(0));
|
|
|
|
}
|
2018-12-16 21:44:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
strip.Show(); delay(animDelay);
|
|
|
|
}
|
|
|
|
}
|
2018-12-09 21:43:08 +01:00
|
|
|
|
2018-12-20 17:45:07 +01:00
|
|
|
|
2018-12-16 22:04:41 +01:00
|
|
|
void playMapAnimation(int animDelay, uint8_t anim[][32]) {
|
|
|
|
for(int frame=0; frame<9; frame++) {
|
2018-12-20 17:45:07 +01:00
|
|
|
for(int n=0; n<strip.PixelCount()/4; n++) {
|
2018-12-16 22:04:41 +01:00
|
|
|
strip.SetPixelColor( 2*n , *c[(anim[frame][n]>>4 )] );
|
|
|
|
strip.SetPixelColor( 2*n+1, *c[(anim[frame][n]&0x0F)] );
|
2018-12-20 17:45:07 +01:00
|
|
|
strip.SetPixelColor( 64+2*n , *c[(anim[frame][n]>>4 )] );
|
|
|
|
strip.SetPixelColor( 64+2*n+1, *c[(anim[frame][n]&0x0F)] );
|
2018-12-16 22:04:41 +01:00
|
|
|
}
|
|
|
|
strip.Show(); delay(animDelay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:06:43 +01:00
|
|
|
void loop() {
|
2018-12-09 22:03:57 +01:00
|
|
|
Serial.println("Entering loop ...");
|
2018-12-11 21:06:43 +01:00
|
|
|
|
2018-12-09 21:43:08 +01:00
|
|
|
// turn off the pixels
|
2018-12-11 21:06:43 +01:00
|
|
|
Serial.println("All off ...");
|
|
|
|
strip.ClearTo(black);
|
2018-12-09 21:43:08 +01:00
|
|
|
|
2018-12-09 22:03:57 +01:00
|
|
|
Serial.println("Animation test ...");
|
2018-12-20 17:45:07 +01:00
|
|
|
playBwAnimation(50, eye_move_cr); delay(3000);
|
2018-12-16 21:44:26 +01:00
|
|
|
playBwAnimation(50, eye_blink_r); delay(5000);
|
|
|
|
playBwAnimation(50, eye_blink_r); delay(3000);
|
|
|
|
playBwAnimation(50, eye_move_rc); delay(3000);
|
|
|
|
playBwAnimation(50, eye_blink_c); delay(3000);
|
|
|
|
playBwAnimation(50, eye_blink_c); delay(4000);
|
|
|
|
playBwAnimation(50, eye_blink_c); delay(3000);
|
|
|
|
playBwAnimation(50, eye_move_cl); delay(3000);
|
|
|
|
playBwAnimation(50, eye_blink_l); delay(2000);
|
2018-12-20 17:45:07 +01:00
|
|
|
playBwAnimation(50, eye_move_lc); delay(3000);
|
|
|
|
|
|
|
|
/*playMapAnimation(150, terminator);delay(3000);*/
|
2018-12-16 22:04:41 +01:00
|
|
|
|
2018-12-20 17:45:07 +01:00
|
|
|
/* for(int n=0; n<strip.PixelCount(); n++) {
|
|
|
|
strip.SetPixelColor(n, 20 );
|
|
|
|
strip.Show(); delay(100);
|
|
|
|
}*/
|
2018-12-16 21:44:26 +01:00
|
|
|
|
|
|
|
/* Serial.println("Colormap test ...");
|
2018-12-11 21:06:43 +01:00
|
|
|
strip.ClearTo(black);
|
2018-12-09 22:03:57 +01:00
|
|
|
for(int n=0; n<strip.PixelCount()/2; n++) {
|
2018-12-11 21:06:43 +01:00
|
|
|
strip.SetPixelColor( 2*n , *c[(test2[n]>>4 )] );
|
|
|
|
strip.SetPixelColor( 2*n+1, *c[(test2[n]&0x0F)] );
|
|
|
|
strip.Show(); delay(1000);
|
2018-12-09 22:03:57 +01:00
|
|
|
}
|
2018-12-16 21:44:26 +01:00
|
|
|
delay(10000);*/
|
2018-12-09 22:03:57 +01:00
|
|
|
|
2018-12-11 21:06:43 +01:00
|
|
|
Serial.println("Loop end ...");
|
2018-12-09 21:43:08 +01:00
|
|
|
}
|