/*-----( Import needed libraries )-----*/ #include #include "nRF24L01.h" #include "RF24.h" #include "printf.h" /*-----( Declare Constants and Pin Numbers )-----*/ #define CE_PIN 9 #define CSN_PIN 10 #define DEBUG 0 #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 = 9; // X -> Maximum of 10 cols. Maximun packet size 32 bytes int rowNum = 9; // Y /*-----( Declare objects )-----*/ RF24 radio(CE_PIN, CSN_PIN); // Create a Radio /*-----( Declare Variables )-----*/ //uint8_t rgb[ 2 + colNum*3 ]; // CMD + Row + 9 rgb //uint8_t rgb[ 2 + colNum*3 ]; // CMD + Row + 9 rgb uint8_t rgb[ 29 ]; // CMD + Row + 9 rgb int counter = 0; int inc = 1; int flag = 0; int i = 0; void setup() /****** SETUP: RUNS ONCE ******/ { if(DEBUG) { Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.println("working..."); } //delay(5000); // wait for open serial port radio.begin(); printf_begin(); radio.setDataRate( RF24_250KBPS ); // Try latency with faster speed radio.setPALevel( RF24_PA_MAX ); radio.setPayloadSize(colNum*3 + 2); radio.setAutoAck(0); radio.openWritingPipe(pipe); radio.printDetails(); }//--(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<32) // buffer protection radio.startWrite( rgb, sizeof(rgb) ); //radio.startWritePowerUp( rgb, sizeof(rgb) ); ///////////////////////////////////////////////////////////////// // ATENTION WITH THIS DELAY! WITH IT WORKS, WITHOUT NO! ////////////////////////////////////////////////////////////// if(DEBUG) { for(i=0; i< 29 ; i++) { Serial.print(rgb[i]); Serial.print(","); } Serial.println(); } else delayMicroseconds(750); //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 )---