-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNeoPixel_my_matrix_sprite.cpp
176 lines (163 loc) · 4.33 KB
/
NeoPixel_my_matrix_sprite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***********************
NeoPixel Matrix Sprite
February 2015
Giovanni Gentile
http://www.0lab.it
Creative Common License
************************/
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#include "Definitions.h"
#include "Shape.h"
// Control PIN
#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
// --------------------------------------------
// Set the color of animation (see Definitions.h)
const uint16_t colors[] = { matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
// Set the brightness (max 50)
int brigh = 40;
// Delay between animation
int wait = 300;
// ---------------------------------------------
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(brigh);
}
// Variable to print text
int x = matrix.width();
int pass = 0;
void loop() {
// Set the color of text (see Definitions.h)
// scrivi("Ciao Amoremiobello", MAGENTA);
// Text change color
// scriviColor("Ciao");
// Set the animation
battito();
pacman();
space();
heart();
}
void sprite(const uint8_t* x, unsigned long y, int w){
byte red = (y & 0xFF0000) >> 16;
byte green = ( y & 0x00FF00) >> 8;
byte blue = (y & 0x0000FF);
matrix.drawBitmap(0,0, x, 8, 8, matrix.Color(red, green, blue));
matrix.show();
delay(w);
matrix.fillScreen(0);
}
void scrivi(String z, unsigned long y) {
int len = z.length();
matrix.fillScreen(0);
matrix.setCursor(x, 0);
byte red = (y & 0xFF0000) >> 16;
byte green = ( y & 0x00FF00) >> 8;
byte blue = (y & 0x0000FF);
matrix.print(z);
if(--x < -len*6) {
x = matrix.width();
}
matrix.setTextColor(matrix.Color(red,green,blue));
matrix.show();
delay(100);
}
void scriviColor(String y) {
int len = y.length();
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(y);
//matrix.print(F("Scrivi"));
if(--x < -len*6) {
x = matrix.width();
if(++pass >= 3) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(100);
}
// ---Animation---
void heart() {
sprite(cuore1,RED,wait);
sprite(cuore1,PINK,wait);
sprite(cuore1,BLUE,wait);
sprite(cuore1,MAGENTA,wait);
}
void space() {
unsigned long COLOR = RED;
sprite(alienoa1,BLUE,wait);
sprite(alienoa2,BLUE,wait);
sprite(alienoa1,BLUE,wait);
sprite(alienob1,COLOR,wait);
sprite(alienob2,COLOR,wait);
sprite(alienob1,COLOR,wait);
sprite(alienoc1,VIOLET,wait);
sprite(alienoc2,VIOLET,wait);
sprite(alienoc1,VIOLET,wait);
sprite(navicella1,COLOR,wait);
sprite(navicella2,COLOR,wait);
sprite(navicella3,COLOR,wait);
sprite(navicella4,COLOR,wait);
}
void pacman() {
sprite(pacman1,YELLOW,wait);
sprite(pacman2,YELLOW,wait);
sprite(pacman1,YELLOW,wait);
sprite(pacman2,YELLOW,wait);
sprite(pacman3,YELLOW,wait);
sprite(pacman4,YELLOW,wait);
sprite(pacman5,YELLOW,wait);
sprite(pacman1,YELLOW,wait);
sprite(pacman2,YELLOW,wait);
sprite(pacman1,YELLOW,wait);
sprite(pacman3,YELLOW,wait);
sprite(gost4,RED,wait);
sprite(gost5,RED,wait);
sprite(gost1,RED,wait);
sprite(gost2,RED,wait);
sprite(gost3,RED,wait);
sprite(gost4,HOTPINK,wait);
sprite(gost5,HOTPINK,wait);
sprite(gost1,HOTPINK,wait);
sprite(gost2,HOTPINK,wait);
sprite(gost3,HOTPINK,wait);
sprite(gost4,ORANGE,wait);
sprite(gost5,ORANGE,wait);
sprite(gost1,ORANGE,wait);
sprite(gost2,ORANGE,wait);
sprite(gost3,ORANGE,wait);
sprite(gost4,AQUA,wait);
sprite(gost5,AQUA,wait);
sprite(gost1,AQUA,wait);
sprite(gost2,AQUA,wait);
sprite(gost3,AQUA,wait);
sprite(pacman1,YELLOW,wait);
sprite(pacman2,YELLOW,wait);
sprite(pacman1,YELLOW,wait);
sprite(pacman2,YELLOW,wait);
sprite(pacman3,YELLOW,wait);
sprite(pacman4,YELLOW,wait);
sprite(pacman5,YELLOW,wait);
sprite(pacman1,YELLOW,wait);
sprite(pacman2,YELLOW,wait);
sprite(pacman1,YELLOW,wait);
sprite(pacman3,YELLOW,wait);
}
void battito() {
sprite(cuore1,RED,400);
sprite(cuore2,RED,200);
sprite(cuore3,RED,100);
sprite(cuore2,RED,200);
sprite(cuore1,RED,400);
sprite(cuore2,RED,200);
sprite(cuore3,RED,100);
sprite(cuore2,RED,200);
}