#include <RGBmatrixPanel.h> //includes the RGB matrix Panel library by Adafruit

//defines the functions on the matrix board to the pins on the arduino
#define CLK 11 
#define OE   9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define D   A3

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64); //calls a RGB matrix Panel library function


//includes the uduino library and gives it a name
#include<Uduino.h>
Uduino uduino("uduinoBoard"); // Declare and name your object

void setup()
{
  Serial.begin(9600); //starts connection with laptop
  matrix.begin(); //calls upon the matrix function

  uduino.addCommand("draw", drawPixel); //the draw function, which is to be called upon from unity to light the right leds up
}

void loop()
{
  uduino.update(); // keeps the uduino functions running
}

//the function that lights up the right led with the right color from Unity
void drawPixel() {
  int x = uduino.charToInt(uduino.getParameter(0));
  int y = uduino.charToInt(uduino.getParameter(1));
  int r = uduino.charToInt(uduino.getParameter(2));
  int g = uduino.charToInt(uduino.getParameter(3));
  int b = uduino.charToInt(uduino.getParameter(4));
  matrix.drawPixel(x, y, matrix.Color333(r, g, b));
}

