150 lines
2.7 KiB
C++
150 lines
2.7 KiB
C++
|
|
/*-----( Import needed libraries )-----*/
|
|
#include <SPI.h>
|
|
#include "nRF24L01.h"
|
|
#include "RF24.h"
|
|
#include "printf.h"
|
|
|
|
|
|
/*-----( Declare Constants and Pin Numbers )-----*/
|
|
#define CE_PIN 9
|
|
#define CSN_PIN 10
|
|
|
|
|
|
#define DEBUG 1
|
|
#define TEST 0
|
|
|
|
// NOTE: the "LL" at the end of the constant is "LongLong" type
|
|
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
|
|
|
|
int row, col;
|
|
int colNum = 5; // X -> Maximum of 10 cols. Maximun packet size 32 bytes
|
|
int rowNum = 13; // Y
|
|
|
|
/*-----( Declare objects )-----*/
|
|
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
|
|
/*-----( Declare Variables )-----*/
|
|
|
|
uint8_t rgb[17]; // CMD + Row + 5 rgb
|
|
int counter = 0;
|
|
int inc = 1;
|
|
int flag = 0;
|
|
int i = 0;
|
|
|
|
void setup() /****** SETUP: RUNS ONCE ******/
|
|
{
|
|
|
|
delay(5000);
|
|
|
|
if(DEBUG)
|
|
Serial.begin(57600);
|
|
|
|
radio.begin();
|
|
printf_begin();
|
|
radio.setDataRate( RF24_250KBPS );
|
|
radio.setPALevel( RF24_PA_MAX );
|
|
radio.setPayloadSize(colNum*3 + 2);
|
|
radio.setAutoAck(0);
|
|
radio.openWritingPipe(pipe);
|
|
radio.printDetails();
|
|
|
|
if(DEBUG)
|
|
Serial.println("working...");
|
|
|
|
|
|
}//--(end setup )---
|
|
|
|
|
|
void loop() /****** LOOP: RUNS CONSTANTLY ******/
|
|
{
|
|
|
|
if(TEST)
|
|
{
|
|
//STROBO LED
|
|
if (flag)
|
|
flag = 0;
|
|
else
|
|
flag = 1;
|
|
|
|
rgb[0] = 1;
|
|
for(int i=1; i<4; i++)
|
|
rgb[i] = 255*flag;
|
|
|
|
radio.startWrite( rgb, sizeof(rgb) );
|
|
delay(100);
|
|
}
|
|
else
|
|
{
|
|
if(MIDIUSB.available() > 0)
|
|
{
|
|
MIDIEvent e;
|
|
e = MIDIUSB.read();
|
|
|
|
if(e.type == 0x04)
|
|
{
|
|
if(e.m1 == 0xF0)
|
|
{
|
|
rgb[0] = e.m2; // CMD
|
|
rgb[1] = e.m3; // ROW
|
|
i = 2;
|
|
}
|
|
else
|
|
{
|
|
rgb[i] = e.m1; // DATA R
|
|
rgb[i+1] = e.m2; // DATA G
|
|
rgb[i+2] = e.m3; // DATA B
|
|
i+=3;
|
|
}
|
|
|
|
}
|
|
else if(e.type == 0x05)
|
|
{
|
|
|
|
if(i<=17) // buffer protection
|
|
radio.startWrite( rgb, sizeof(rgb) );
|
|
|
|
for(i=0; i< 17 ; i++)
|
|
{
|
|
Serial.print(rgb[i]);
|
|
Serial.print(",");
|
|
}
|
|
Serial.println();
|
|
|
|
//if(rgb[1] == 1) // row 1
|
|
// analogWrite(5, rgb[2]); // col1
|
|
|
|
//if(DEBUG)
|
|
// Serial.print(".");
|
|
|
|
}
|
|
|
|
|
|
// if(DEBUG)
|
|
// {
|
|
// if(e.type != 0x0F) // timestamp 1 BYTE
|
|
// {
|
|
// //Serial.print("Midi Packet: ");
|
|
// Serial.print(e.type);
|
|
// Serial.print("\t");
|
|
// Serial.print(e.m1);
|
|
// Serial.print("\t");
|
|
// Serial.print(e.m2);
|
|
// Serial.print("\t");
|
|
// Serial.println(e.m3);
|
|
// }
|
|
//
|
|
// }
|
|
|
|
//MIDIUSB.flush(); // si se pone se cuelga al poco rato
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}//--(end main loop )---
|
|
|
|
|
|
|
|
|
|
|