Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <RGBmatrixPanel.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_mfGFX.h>

// testshapes demo for Adafruit RGBmatrixPanel library.
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 32x32 RGB LED matrix:
// http://www.adafruit.com/products/607

// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
// for Adafruit Industries.
// BSD license, all text above must be included in any redistribution.

#include <string>
#include "math.h"


// Modify for version of RGBShieldMatrix that you have
// HINT: Maker Faire 2016 Kit and later have shield version 4 (3 prior to that)
//
// NOTE: Version 4 of the RGBMatrix Shield only works with Photon and Electron (not Core)
#define RGBSHIELDVERSION		4

/** Define RGB matrix panel GPIO pins **/

	#warning "old shield"
	#define CLK	D6
	#define OE 	D7
	#define LAT	A4
	#define A 	A0
	#define B 	A1
	#define C 	A2
	#define D	A3

/****************************************/


RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, true, 32);


//int buttonPin = D3;
// int servoPin = A3;
// Servo myServo;
// int servoPos = 0;
long lastPublishedAt = 0;
// this is the time delay before we should publish a new event
// from this device
int publishAfter = 10000;
int state = 0; //off mode

String message = ""; 
int textX = matrix.width();
int textMin = sizeof(message) * -15;
int hue = 0;
int count = 0;
int intdata = 2;


  // myServo.write( 180 );
int8_t ball[3][4] = {
  { 3, 0, 1, 1 }, // Initial X,Y pos & velocity for 3 bouncy balls
  { 17, 15, 1, -1 },
  { 27, 4, -1, 1 } 
  };


static const uint16_t ballcolor[3] = {
  0x0080, // Green=1
  0x0002, // Blue=1
  0x1000 // Red=1
  };

void setup() {
  matrix.begin();
  matrix.setTextWrap(false); // Allow text to run off right edge
  matrix.setTextSize(2);
  Particle.subscribe( "diot/2019/smartstudio/supporter" , handleSharedEventPrint );
  Particle.subscribe( "diot/2019/smartstudio/feelometer" , handleSharedEvent );
}


void loop() 
{
  
  if (state == 0)
  {
  if (intdata >= 1 && intdata <= 3)
  {
  message = "It's been a good dayyy!!!";
  
  byte i;
  // Clear background
  matrix.fillScreen(0);
  
  //Bounce three balls around
  for(i=0; i<3; i++) 
  {
  // Draw 'ball'
  matrix.fillCircle(ball[i][0], ball[i][1], 5, ballcolor[i]);
  // Update X, Y position
  ball[i][0] += ball[i][2];
  ball[i][1] += ball[i][3];
  // Bounce off edges
  if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
  ball[i][2] *= -1;
  if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
  ball[i][3] *= -1;
  
  }
  // Draw big scrolly text on top
  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  // matrix.setTextColor(matrix.Color888(66, 0, 0, true));
  matrix.setCursor(textX, 8);
  matrix.print(message);
  
  //Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;
  
  // Update display
  matrix.swapBuffers(false);
  
  delay(50);	// Slow down animation
  
  
  
  }
  
  else if (intdata > 3)
  {
  message = "Hey studio needs some love!";
  
  byte i;
  // Clear background
  
  matrix.fillRect(0, 0, 32, 32, matrix.Color333(0,0,3));
  // //Bounce three balls around
  // for(i=0; i<3; i++) 
  // {
  // // Draw 'ball'
  // matrix.fillCircle(ball[i][0], ball[i][1], 5, ballcolor[i]);
  // // Update X, Y position
  // ball[i][0] += ball[i][2];
  // ball[i][1] += ball[i][3];
  // // Bounce off edges
  // if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
  // ball[i][2] *= -1;
  // if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
  // ball[i][3] *= -1;
  
  // }
  // Draw big scrolly text on top
  matrix.setTextColor(matrix.ColorHSV(151, 151, 151, true));
  matrix.setCursor(textX, 8);
  matrix.print(message);
  
  //Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  // hue += 7;
  // if(hue >= 1536) hue -= 1536;
  
  // Update display
  matrix.swapBuffers(false);
  
  delay(50);	// Slow down animation
  
  
  
  }
  
  }
}
  


// A character array that contains the data published in the event we're responding to.
void handleSharedEventPrint(const char *event, const String data)
{
  state=1;
  message = data;
  matrix.fillScreen(0);
  for (int ii=0; ii<500; ii++)
  {
  byte i;
  // Clear background
  matrix.fillScreen(0);
  //Bounce three balls around
  for(i=0; i<3; i++) 
  {
  // Draw 'ball'
  matrix.fillCircle(ball[i][0], ball[i][1], 5, ballcolor[i]);
  // Update X, Y position
  ball[i][0] += ball[i][2];
  ball[i][1] += ball[i][3];
  // Bounce off edges
  if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
  ball[i][2] *= -1;
  if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
  ball[i][3] *= -1;
  
  }
  // Draw big scrolly text on top
  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  matrix.setCursor(textX, 8);
  matrix.print(message);
  
  //Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;
  
  // Update display
  matrix.swapBuffers(false);
  
  delay(50);	// Slow down animation
  
  }
  state=0;
}

void handleSharedEvent(const char *event, const char *data)
{
  int intdata = data - "0";
  
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0