7 #include <SoftwareWire.h>
9 #define DISPLAY_ADDRESS 0x65
10 #define SWIPE_SPEED 75
11 #define SWIPE_FRONT_ONE 0xb1
12 #define SWIPE_FRONT_TWO 0
13 #define SWIPE_REAR_ONE 0x5e
14 #define SWIPE_REAR_TWO 0x24
15 #define SWIPE_DELAY 500
71 PSIMatrix(
const byte sdaPin,
const byte sclPin,
const byte psi) :
72 SoftwareWire(sdaPin, sclPin),
99 if (*cmd++ ==
'P' && *cmd++ ==
'S')
101 long int cmdvalue = 0;
103 while (*c >=
'0' && *c <=
'9')
105 cmdvalue = cmdvalue * 10 + (*c++ -
'0');
116 selectEffect((
long int)seq * 10000L + (
long int)speedScale * 100 + numSeconds);
124 unsigned long currentMillis = millis();
125 if (currentMillis >= fSwipeSpeed)
127 swipe_main(swipe_position,100,
true, 1);
128 if (swipe_direction == 0) {
129 if (swipe_position > 7) {
131 fSwipeSpeed = currentMillis + random(500, 2000);
138 if (swipe_position <= 0) {
140 fSwipeSpeed = currentMillis + random(500, 2000);
152 int swipe_direction = 0;
153 int swipe_position = 0;
154 unsigned long fSwipeSpeed;
155 unsigned long fSwipeMillis;
158 uint64_t heart[32] = {
198 int i2cSendBytes(uint8_t *data, uint8_t len)
202 ret = write(data, len);
208 void displayFrames(uint64_t *buffer, uint16_t duration_time,
bool forever_flag, uint8_t frames_number)
211 uint8_t data[72] = {0, };
213 if (frames_number > 5) frames_number = 5;
214 else if (frames_number == 0)
return;
220 data[4] = frames_number;
222 for (
int i=frames_number-1;i>=0;i--)
226 for (
int j = 0; j< 8; j++)
228 for (
int k = 7; k >= 0; k--)
230 data[8+j*8+(7-k)] = ((uint8_t *)buffer)[j*8+k+i*64];
237 data[1] = (uint8_t)(duration_time & 0xff);
238 data[2] = (uint8_t)((duration_time >> 8) & 0xff);
239 data[3] = forever_flag;
242 i2cSendBytes(data, 72);
247 void displayFrames(uint8_t *buffer, uint16_t duration_time,
bool forever_flag, uint8_t frames_number)
249 uint8_t data[72] = {0, };
251 if (frames_number > 5) frames_number = 5;
252 else if (frames_number == 0)
return;
258 data[4] = frames_number;
260 for (
int i=frames_number-1;i>=0;i--)
263 for (
int j=0;j<64;j++) data[8+j] = buffer[j+i*64];
267 data[1] = (uint8_t)(duration_time & 0xff);
268 data[2] = (uint8_t)((duration_time >> 8) & 0xff);
269 data[3] = forever_flag;
271 i2cSendBytes(data, 72);
276 void swipe_main(uint8_t pos, uint16_t duration_time,
bool forever_flag, uint8_t frames_number)
280 uint8_t data[72] = {0, };
286 data[4] = frames_number;
289 for (
int j = 0; j< 8; j++)
291 for (
int k = 7; k >= 0; k--)
307 data[8+j*8+(7-k)] = colour;
310 data[1] = (uint8_t)(duration_time & 0xff);
311 data[2] = (uint8_t)((duration_time >> 8) & 0xff);
312 data[3] = forever_flag;
319 i2cSendBytes(data, 72);
325 void do_heart(uint8_t cycles, uint8_t pulse_speed)
327 for(
int i=0;i<cycles;i++)
329 for (
int i=0;i<4;i++)
331 displayFrames(heart+i*8, 100,
true, 1);
340 void do_random(uint8_t cycles, uint8_t pulse_speed)
342 uint8_t data[64] = {0, };
345 for(
int i=0;i<=cycles;i++)
347 for (
int j = 0; j< 8; j++)
349 for (
int k = 7; k >= 0; k--)
351 pixel = random(0,cycles);
352 if (pixel < cycles-i)
355 colour = random(0,250);
359 data[j*8+(7-k)] = colour;
362 displayFrames(data, 100,
true, 1);
365 uint8_t blank[64] = {0xff, };
366 for(
int i = 0; i <
sizeof(blank); ++i )
367 blank[i] = (
char)255;
368 displayFrames(blank, 100,
true, 1);
#define SWIPE_REAR_ONE
Definition: PSIMatrix.h:13
#define SWIPE_FRONT_ONE
Definition: PSIMatrix.h:11
#define DISPLAY_ADDRESS
Definition: PSIMatrix.h:9
#define SWIPE_REAR_TWO
Definition: PSIMatrix.h:14
#define SWIPE_SPEED
Definition: PSIMatrix.h:10
#define SWIPE_FRONT_TWO
Definition: PSIMatrix.h:12
#define DEBUG_PRINT(s)
Definition: ReelTwo.h:154
#define DEBUG_PRINTF(s)
Definition: ReelTwo.h:155
#define DEBUG_PRINTLN(s)
Definition: ReelTwo.h:152
Base class for all animated devices.
Definition: AnimatedEvent.h:19
Base class for all command enabled devices.
Definition: CommandEvent.h:18
PSIMatrix by Darren Poulson daz@r2djp.co.uk
Definition: PSIMatrix.h:41
virtual void setup() override
Subclasses must implement this function to perform any necessary setup that cannot happen in the cons...
Definition: PSIMatrix.h:64
void selectEffect(long inputNum)
Select the specified effect using a 32-bit integer.
Definition: PSIMatrix.h:89
EffectValue
Definition: PSIMatrix.h:44
@ kNormalVal
Definition: PSIMatrix.h:45
PSIID
Definition: PSIMatrix.h:57
@ kRearPSI
Rear PSI ID.
Definition: PSIMatrix.h:61
@ kFrontPSI
Front PSI ID.
Definition: PSIMatrix.h:59
PSIMatrix(const byte sdaPin, const byte sclPin, const byte psi)
Constructor.
Definition: PSIMatrix.h:71
void setSequence(Sequence seq=kNormal, uint8_t speedScale=0, uint8_t numSeconds=0)
Select the specified effect sequence.
Definition: PSIMatrix.h:114
virtual void handleCommand(const char *cmd) override
Command Prefix: PS.
Definition: PSIMatrix.h:97
Sequence
Definition: PSIMatrix.h:49
@ kHeart
Definition: PSIMatrix.h:52
@ kNormal
Definition: PSIMatrix.h:50
@ kMalf
Definition: PSIMatrix.h:53
@ kSolid
Definition: PSIMatrix.h:51
virtual void animate() override
Perform a single frame of LED animation based on the selected sequence.
Definition: PSIMatrix.h:122
Utility class to control a VMusic2 module.
Definition: SetupEvent.h:16