You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.6 KiB

#include <Arduino.h>
//DMX stuff
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
const int universeSize = 512;
// ethernet stuff
#include <UIPEthernet.h>
const IPAddress ip(10, 255, 255, 255);
uint8_t mac[] = {0xAA, 0xDD, 0xBB, 0xAA, 0xDD, 0xBB};
//ArtNet stuff
#include <UIPArtnet.h>
ArtnetReceiver artnet;
uint32_t universe0 = 0;
uint32_t universe1 = 1;
//NRF stuff
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
RF24 radio (0, 1);
const uint16_t address = 0xADB0;
uint64_t datasend;
//RGB LED
const int statusLED[] = {23,22, 21}; //RGB
const int statusLEDlength = 3;
int statusLEDstat[3];
//define min interval to show error
unsigned long currentTime = millis();
unsigned long previousTime = 0;
const long waitTime = 100;
const long errorTime = 5000;
//ArtNet universe0 callback
void callback(byte* artnetdata, uint16_t size) {
digitalWrite(10, HIGH);
//RGB PWM
//setRGB(artnetdata[0], artnetdata[1], artnetdata[2]);
//DMX output
DMX.beginTransmission();
for (int i = 0; i < universeSize; ++i) {
DMX.write(i, artnetdata[i]);
}
DMX.endTransmission();
//send NRF
for (int i = 0; i < 20; i++) {
datasend = i; //package ID
for (int j = 0; j < 7; j++) {
datasend = (datasend << 8) + artnetdata[7 * i + j];
}
radio.writeFast(&datasend, sizeof(datasend));
}
digitalWrite(10, LOW);
}
void setRGB(int r, int g, int b){
if (r != statusLEDstat[0]) analogWrite(statusLED[0], r);
if (g != statusLEDstat[1]) analogWrite(statusLED[1], g);
if (b != statusLEDstat[2]) analogWrite(statusLED[2], b);
statusLEDstat[0] = r;
statusLEDstat[1] = g;
statusLEDstat[2] = b;
}
//setup
void setup() {
for (int i : statusLED){
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
pinMode(10, OUTPUT);
digitalWrite(10, LOW);
//start DMX
DMX.begin(universeSize);
//start ethernet
Ethernet.begin(mac, ip);
//start ArtNet
artnet.begin();
artnet.subscribe(universe0, callback);
//start NRF
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_1MBPS);
//radio.disableDynamicPayloads();
radio.setAutoAck(false);
radio.disableCRC();
radio.stopListening();
setRGB(0,0,255);
delay(200);
}
void loop() {
currentTime = millis();
if (artnet.parse()) { // check if artnet packet has come and execute callback
previousTime = currentTime;
setRGB(0,255,0);
}else if(currentTime - previousTime >= errorTime){
setRGB(255,0,0);
}else if(currentTime - previousTime >= waitTime){
setRGB(0,0,255);
}
}