You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
//NRF stuff
|
|
#include <SPI.h>
|
|
#include <RF24.h>
|
|
#include <nRF24L01.h>
|
|
|
|
RF24 radio (7, 8);
|
|
|
|
const uint16_t address = 0xADB0;
|
|
uint64_t datareceive;
|
|
|
|
//Neopixel stuff
|
|
#include <Adafruit_NeoPixel.h>
|
|
#ifdef __AVR__
|
|
#include <avr/power.h>
|
|
#endif
|
|
#define NEOPIN 6
|
|
#define NUMPIXELS 48
|
|
#define NEOSTART 0
|
|
Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIN, NEO_GRB + NEO_KHZ800);
|
|
byte neodata[512];
|
|
|
|
void setup() {
|
|
pinMode(9, OUTPUT);
|
|
|
|
//start NRF
|
|
radio.begin();
|
|
radio.openReadingPipe(0, address);
|
|
radio.setPALevel(RF24_PA_LOW);
|
|
radio.setDataRate(RF24_1MBPS);
|
|
radio.setAutoAck(false);
|
|
radio.disableCRC();
|
|
radio.startListening();
|
|
|
|
//start Neopixels
|
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
|
clock_prescale_set(clock_div_1);
|
|
#endif
|
|
pixels.begin();
|
|
|
|
}
|
|
|
|
void loop() {
|
|
//NRF receive
|
|
for (int i = 0; i < 20; i++) { //count packages
|
|
do {
|
|
while (!radio.available()); //wait for NRF
|
|
radio.read(&datareceive, sizeof(datareceive)); //get NRF data
|
|
} while (i != ((datareceive >> 8 * 7) & 0xFF)); //wait for right package ID
|
|
digitalWrite(9, HIGH);
|
|
for (int j = 0; j < 7; j++) { //count bytes
|
|
neodata[7 * i + j] = (datareceive >> 48 - 8 * j) & 0xFF; //bytes to array
|
|
//Serial.print(DMXdata[7 * i + j], HEX); //print data
|
|
//Serial.print(", ");
|
|
}
|
|
}
|
|
|
|
pixels.clear(); //clear Neopixels
|
|
for (int i = 0; i < 48; ++i) {
|
|
pixels.setPixelColor(i, pixels.Color(neodata[i * 3 + 0 + NEOSTART], neodata[i * 3 + 1 + NEOSTART], neodata[i * 3 + 2 + NEOSTART])); //write Neopixel data
|
|
}
|
|
pixels.show(); //send Neopixel data
|
|
|
|
digitalWrite(9, LOW);
|
|
}
|