change pins for pcb and optimize

master
adb 4 years ago
parent a8c2813b74
commit 2c9913b9c2

@ -8,22 +8,11 @@ const int universeSize = 512;
ArtnetReceiver artnet;
uint32_t universe0 = 0;
uint32_t universe1 = 1;
byte artnetdata[512];
// ethernet stuff
const IPAddress ip(10, 255, 255, 255);
uint8_t mac[] = {0xAA, 0xDD, 0xBB, 0xAA, 0xDD, 0xBB};
//ArtNet universe0 callback
void callback(byte* data, uint16_t size) {
for (size_t i = 0; i < 512; ++i) {
artnetdata[i] = data[i];
//if (i == 0) analogWrite(30, data[i]);
//if (i == 1) analogWrite(8, data[i]);
//if (i == 2) analogWrite(9, data[i]);
}
}
//NRF stuff
#include <SPI.h>
#include <RF24.h>
@ -34,13 +23,25 @@ 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;
//setup
void setup() {
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
for (int i=0; i < statusLEDlength; i++){
pinMode(statusLED[i], OUTPUT);
digitalWrite(statusLED[i], LOW);
}
pinMode(10, OUTPUT);
digitalWrite(10, LOW);
//start DMX
DMX.begin(universeSize);
@ -62,26 +63,27 @@ void setup() {
radio.disableCRC();
radio.stopListening();
analogWrite(12, 20);
delay(100);
setRGB(0,0,255);
delay(200);
}
void loop() {
//int timebegin = millis();
//get ArtNet package
while(!artnet.parse());
digitalWrite(15, HIGH);
/*if (artnet.parse()) { // check if artnet packet has come and execute callback
digitalWrite(31, HIGH);
}*/
//uint64_t nrfpackage = artnetdata[0];
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);
}
}
//ArtNet universe0 callback
void callback(byte* artnetdata, uint16_t size) {
digitalWrite(10, HIGH);
//RGB PWM
analogWrite(12, artnetdata[0]);
analogWrite(13, artnetdata[1]);
analogWrite(14, artnetdata[2]);
//setRGB(artnetdata[0], artnetdata[1], artnetdata[2]);
//DMX output
DMX.beginTransmission();
@ -99,11 +101,14 @@ void loop() {
}
radio.writeFast(&datasend, sizeof(datasend));
}
digitalWrite(10, LOW);
}
//int timeend = millis();
//int timeneeded = timeend - timebegin;
//if (timeneeded < 20) delay(20 - timeneeded);
digitalWrite(15, 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;
}

@ -38,7 +38,7 @@ void setup() {
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_1MBPS);
radio.setDataRate(RF24_2MBPS);
radio.setAutoAck(false);
radio.disableCRC();
radio.startListening();

Loading…
Cancel
Save