Created
June 10, 2014 05:57
-
-
Save puttputt/140716cbe6504267d064 to your computer and use it in GitHub Desktop.
superhat v1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_NeoMatrix.h> | |
#define PIN 9 | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(77, PIN, NEO_GRB + NEO_KHZ800); | |
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(11, 7, PIN, | |
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + | |
NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, | |
NEO_GRB + NEO_KHZ800); | |
uint8_t rows = 7; | |
uint8_t cols = 11; | |
uint32_t off = strip.Color(0,0,0); | |
uint32_t green_100 = strip.Color(0, 127, 0); | |
uint32_t green_75 = strip.Color(0, 64, 0); | |
uint32_t green_50 = strip.Color(0, 31, 0); | |
uint32_t green_25 = strip.Color(0, 15, 0); | |
uint32_t green_15 = strip.Color(0, 7, 0); | |
uint16_t pos = 27; | |
uint8_t canada[77] = { | |
1,1,2,2,2,2,2,2,2,1,1, | |
1,1,2,2,2,1,2,2,2,1,1, | |
1,1,2,2,1,1,1,2,2,1,1, | |
1,1,2,1,1,1,1,1,2,1,1, | |
1,1,2,2,1,1,1,2,2,1,1, | |
1,1,2,2,2,1,2,2,2,1,1, | |
1,1,2,2,2,2,2,2,2,1,1 }; | |
uint32_t canada_colours[2] = {strip.Color(64,0,0), strip.Color(32,32,32) }; | |
uint8_t space[77] = { | |
0,0,0,1,1,1,1,1,0,0,0, | |
0,0,1,1,1,1,1,1,1,0,0, | |
0,1,1,2,1,1,1,2,1,1,0, | |
1,1,1,1,1,1,1,1,1,1,1, | |
1,0,1,1,1,1,1,1,1,0,1, | |
1,0,1,0,0,0,0,0,1,0,1, | |
0,0,0,1,1,0,1,1,0,0,0 | |
}; | |
uint32_t space_colours[2] = { strip.Color(40,0,95), strip.Color(0,127,0) }; | |
uint8_t heart[77] = { | |
0,1,1,0,0,0,0,1,1,0,0, | |
1,1,1,1,0,0,1,1,1,1,0, | |
1,1,1,1,1,1,1,1,1,1,0, | |
0,1,1,1,1,1,1,1,1,0,0, | |
0,0,1,1,1,1,1,1,0,0,0, | |
0,0,0,1,1,1,1,0,0,0,0, | |
0,0,0,0,1,1,0,0,0,0,0, | |
}; | |
uint32_t heart_colours[1] = { strip.Color(127,0,0) }; | |
uint8_t star[77] = { | |
0,0,0,0,0,1,0,0,0,0,0, | |
0,0,0,0,1,1,1,0,0,0,0, | |
0,1,1,1,1,1,1,1,1,1,0, | |
0,0,1,1,1,1,1,1,1,0,0, | |
0,0,0,1,1,1,1,1,0,0,0, | |
0,0,1,1,1,0,1,1,1,0,0, | |
0,1,1,0,0,0,0,0,1,1,0 | |
}; | |
uint32_t star_colours[1] = { strip.Color(64,64,0) }; | |
uint8_t smile[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,1,1,0,1,1,0,0,0, | |
0,0,0,1,1,0,1,1,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,1,0,0,0,0,0,1,0,0, | |
0,0,0,1,0,0,0,1,0,0,0, | |
0,0,0,0,1,1,1,0,0,0,0, | |
}; | |
uint8_t p1[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,1,1,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p2[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,1,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p3[77] = { | |
0,0,0,0,1,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p4[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,1,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p5[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,1,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p6[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,1,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p7[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,1,1,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p8[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,1,0,1,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p9[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,1,0,0,0,0, | |
}; | |
uint8_t p10[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,1,0,0,0,1,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p11[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,1,0,0,0,0,1,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p12[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,1,0,1,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p13[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,1,0,0,0,0,0,0,1,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p14[77] = { | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
}; | |
uint8_t p15[77] = { | |
1,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,1,0, | |
0,1,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0, | |
}; | |
uint32_t pongColours = strip.Color(42,42,42); | |
uint32_t smile_colours[1] = { strip.Color(127, 65, 0) }; | |
void setup() { | |
strip.begin(); | |
matrix.begin(); | |
strip.setBrightness(50); | |
matrix.setBrightness(50); | |
matrix.show(); | |
strip.show(); // Initialize all pixels to 'off' | |
} | |
const uint16_t colors[] = { | |
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) }; | |
int x = matrix.width(); | |
void loop() { | |
pong(); | |
pong(); | |
words("Game"); | |
words("Over"); | |
fillRandom(); | |
resetStrip(); | |
colorWipe(RandomColour(), 25); | |
resetStrip(); | |
words("BONNA"); | |
words("ROO"); | |
colorWipe(RandomColour(), 25); | |
rainbow(20); | |
theMatrix(); | |
draw(space_colours, space); | |
theMatrix(); | |
theaterChaseRainbow(50); | |
theaterChase(strip.Color(64, 0, 0), 100); | |
draw(canada_colours, canada); | |
theaterChase(strip.Color(32, 32, 32), 100); | |
draw(heart_colours, heart); | |
theMatrix(); | |
words("such"); | |
words("fun"); | |
words("wow"); | |
//rainbowCycle(20); | |
draw(star_colours, star); | |
theMatrix(); | |
words("FREE"); | |
words("HUGS"); | |
theMatrix(); | |
words("TURN"); | |
words("UP"); | |
//theaterChaseRainbow(50); | |
theMatrix(); | |
words("DANCE"); | |
words("YOUR"); | |
words("HEART"); | |
words("OUT"); | |
} | |
void draw(uint32_t colours[], uint8_t design[]) | |
{ | |
for(int i=0; i < 77; i++) | |
{ | |
if(design[i] != 0) | |
{ | |
strip.setPixelColor(i, colours[design[i]-1]); | |
strip.show(); | |
} | |
} | |
delay(4000); | |
} | |
void words(String words) | |
{ | |
int pass = 0; | |
while(pass < 1) | |
{ | |
matrix.fillScreen(0); | |
matrix.setCursor(x, 0); | |
matrix.print(words); | |
if(--x < -22) { | |
x = matrix.width(); | |
pass++; | |
matrix.setTextColor(RandomColour()); | |
} | |
matrix.show(); | |
delay(75); | |
} | |
} | |
void resetStrip() | |
{ | |
for(int i=0; i < 77; i++) | |
{ | |
strip.setPixelColor(i, off); | |
} | |
strip.show(); | |
} | |
void pong() | |
{ | |
//printPong(p1); | |
//printPong(p2); | |
//printPong(p3); | |
printPong(p4); | |
printPong(p5); | |
printPong(p6); | |
printPong(p7); | |
printPong(p8); | |
printPong(p9); | |
printPong(p10); | |
printPong(p11); | |
printPong(p12); | |
printPong(p13); | |
printPong(p14); | |
printPong(p15); | |
} | |
void printPong(uint8_t scene[]) | |
{ | |
for(int i=0; i<77; i++) | |
{ | |
if(scene[i] != 0) | |
{ | |
strip.setPixelColor(i, pongColours); | |
} | |
else | |
{ | |
strip.setPixelColor(i, off); | |
} | |
} | |
strip.show(); | |
delay(200); | |
} | |
void theMatrix() | |
{ | |
for(uint16_t i=0; i<rows+5; i++) { | |
for(uint16_t j=0; j < cols; j++) | |
{ | |
strip.setPixelColor((i-5)*cols+j, off); | |
strip.setPixelColor((i-4)*cols+j, green_15); | |
strip.setPixelColor((i-3)*cols+j, green_25); | |
strip.setPixelColor((i-2)*cols+j, green_50); | |
strip.setPixelColor((i-1)*cols+j, green_75); | |
strip.setPixelColor(i*cols+j, green_100); | |
} | |
strip.show(); | |
delay(100); | |
} | |
} | |
void fillRandom() | |
{ | |
int i=-1; | |
boolean on[77]; | |
boolean done = false; | |
//initialize array | |
for(int k=0; k<77; k++) | |
{ | |
on[k] = false; | |
} | |
while(done == false) { | |
i = random(0,77); | |
if(on[i] == false) | |
{ | |
strip.setPixelColor(i, RandomColour()); | |
strip.show(); | |
delay(100); | |
on[i] = true; | |
} | |
for(int j=0; j<77; j++) | |
{ | |
if(on[j] == false) | |
{ | |
done = false; | |
break; | |
} | |
done = true; | |
} | |
} | |
} | |
// Fill the dots one after the other with a color | |
void colorWipe(uint32_t c, uint8_t wait) { | |
for(uint16_t i=0; i<strip.numPixels(); i++) { | |
strip.setPixelColor(i, c); | |
strip.show(); | |
delay(wait); | |
} | |
} | |
void rainbow(uint8_t wait) { | |
uint16_t i, j; | |
for(j=0; j<256; j++) { | |
for(i=0; i<strip.numPixels(); i++) { | |
strip.setPixelColor(i, Wheel((i+j) & 127)); | |
} | |
strip.show(); | |
delay(wait); | |
} | |
} | |
// Slightly different, this makes the rainbow equally distributed throughout | |
void rainbowCycle(uint8_t wait) { | |
uint16_t i, j; | |
for(j=0; j<127*5; j++) { // 5 cycles of all colors on wheel | |
for(i=0; i< strip.numPixels(); i++) { | |
strip.setPixelColor(i, Wheel(((i * 127 / strip.numPixels()) + j) & 127)); | |
} | |
strip.show(); | |
delay(wait); | |
} | |
} | |
//Theatre-style crawling lights. | |
void theaterChase(uint32_t c, uint8_t wait) { | |
for (int j=0; j<10; j++) { //do 10 cycles of chasing | |
for (int q=0; q < 3; q++) { | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, c); //turn every third pixel on | |
} | |
strip.show(); | |
delay(wait); | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, 0); //turn every third pixel off | |
} | |
} | |
} | |
} | |
//Theatre-style crawling lights with rainbow effect | |
void theaterChaseRainbow(uint8_t wait) { | |
for (int j=0; j < 127; j++) { // cycle all 256 colors in the wheel | |
for (int q=0; q < 3; q++) { | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, Wheel( (i+j) % 127)); //turn every third pixel on | |
} | |
strip.show(); | |
delay(wait); | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, 0); //turn every third pixel off | |
} | |
} | |
} | |
} | |
// Input a value 0 to 255 to get a color value. | |
// The colours are a transition r - g - b - back to r. | |
uint32_t Wheel(byte WheelPos) { | |
if(WheelPos < 42) { | |
return strip.Color(WheelPos * 3,127 - WheelPos * 3, 0); | |
} | |
else if(WheelPos < 85) { | |
WheelPos -= 85; | |
return strip.Color(127 - WheelPos * 3, 0, WheelPos * 3); | |
} | |
else { | |
WheelPos -= 170; | |
return strip.Color(0, WheelPos * 3, 127 - WheelPos * 3); | |
} | |
} | |
uint32_t RandomColour() | |
{ | |
uint8_t first = random(42,127); | |
uint8_t second = random(42,127); | |
uint8_t third = random(42,127); | |
return strip.Color(first, second, third); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment