Hi all, first post here, and relatively new to Arduino in general, but versed in c++ and to a lesser extent EE.
I'm working on a project for DMX control of a RGB + Amber LED lighting fixture, and am using an Uno + the tinker kit DMX master shield. I've also built an analog sound sensor with a lowpass filter to detect the beat of music, run thru an op-amp (plug in your music instead of using a microphone). The sound sensor works fine, the serial works fine, I can output DMX signals to the lighting fixture UNTIL...
I wrote a library for the purpose of having a number of preset colors that could be selected at random / at will within the given logic for the programming. One example is on a sound trigger, pick another random color from the library and send to the fixture through DMX. When I include this library and create an object from the class the serial monitor has no output and the program does not run. I have absolutely no clue as to why this is but I have isolated that the serial monitor does not output when I include the line that initializes the class (line 4). Code is below.
Any insight is much appreciated!
Client code
#include <DmxSimple.h>
#include <RGBA_LIB.h>
RGBA_LIB colorgen;
color fixture;
int analogPin = 5;
int val;
int threshold = 100;
void setup() {
Serial.begin(9600);
}
void loop(){
val = analogRead(analogPin);
if(val > threshold){
fixture = colorgen.random();
DmxSimple.write(1, fixture.R);
DmxSimple.write(2, fixture.G);
DmxSimple.write(3, fixture.B);
DmxSimple.write(4, fixture.A);
DmxSimple.write(5, 255);
DmxSimple.write(6, 0);
DmxSimple.write(7, 0);
DmxSimple.write(8, 0);
delay(100);
}else{
DmxSimple.write(5, 0);
delay(25);
}
}
Header file
#ifndef RGBA_LIB_H
#define RGBA_LIB_H
#include <Arduino.h>
struct color{
int R, G, B, A;
};
class RGBA_LIB{
color list[48];
int i;
public:
RGBA_LIB();
~RGBA_LIB();
color random();
};
#endif
Implementation file
#include <RGBA_LIB.h>
#include <Arduino.h>
RGBA_LIB::RGBA_LIB(){
color AA = {255, 0, 0, 0};
list[0] = AA;
color AB = {0, 255, 0, 0};
list[1] = AB;
color AC = {0, 0, 255, 0};
list[2] = AC;
color AD = {0, 0, 0, 255};
list[3] = AD;
// many more colors after this
}
RGBA_LIB::~RGBA_LIB(){
}
color RGBA_LIB::random(){
//choose i
int i = rand() % 67;
return list[i];
}