/*
Forum: https://forum.arduino.cc/t/arduino-uno-ledstrip-issue/1400615
Wokwi: https://wokwi.com/projects/423791454389927937
Changes done to original sketch:
* const int Channel is outcommented - not used here
* NUM_CHAN set to 51
* NUM_LEDS equals NUm_CHAN so that a change of NUM_CHAN also changes NUM_LEDS
* //DMX[i]= (recv.dmx(Channel[i])); outcommented and replaced by DMX[i]= random(0,256);
* Led.show(); has been moved outside the for-loop; makes sense to call show after all changes are done
* Added delay(100) in loop to slow down the color changes
Effect found:
* works for up to 51 channels/leds
* does not work for 52 or more
*/
#include "Ethernet.h"
#include "sACN.h"
#include "Adafruit_NeoPixel.h"
//Setup Ethernet
uint8_t mac[] = {0x90, 0xA2, 0xDA, 0x10, 0x14, 0x48};
IPAddress ip(169, 254, 89, 67);
IPAddress dns(169, 254, 89, 1);
IPAddress gateway(169, 254, 89, 1);
IPAddress subnet(255, 255, 0, 0);
//Setup sACN
EthernetUDP sacn;
Receiver recv(sacn);
const int Universe= 32;
const int NUM_CHAN= 51;
//const int Channel[NUM_CHAN]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36};
int DMX[NUM_CHAN];
//Setup LED
const int DATA_PIN= 7;
const int NUM_LEDS= NUM_CHAN;
Adafruit_NeoPixel Led(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
// Define colours
#define On 255,75,0
#define Off 0,65,255
#define Other 255,0,0
#define None 0,0,0
int Brightness=100;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, dns, gateway, subnet);
recv.begin(Universe);
Led.begin();
Led.clear();
Led.show();
Led.setBrightness(Brightness);
}
void loop() {
recv.update();
for (int i=0; i<NUM_CHAN; i++){
// Read Channel input, Write to DMX value
//DMX[i]= (recv.dmx(Channel[i]));
DMX[i]= random(0,256);
//Apply values to Leds
if (DMX[i]> 127){
Led.setPixelColor(i, Led.Color(On));
} else {
Led.setPixelColor(i, Led.Color(Off));
}
}
Led.show();
delay(100);
}