void RGBElement::setBrightness(byte value)
{
    if(value>0)
    {
        m_brightness = value;
    }
    else
    {
        m_brightness = 1;
    }
    writeRGB();
}
void RGBElement::setRGB(byte R, byte G, byte B, bool force)
{
    if((m_Ract != R)||(m_Gact != G)||(m_Bact !=B))
    {
        m_Rnext = R;
        m_Gnext = G;
        m_Bnext = B;
        m_sync = force;
    }
    if(force) {
        switchColor();
        writeRGB();
    }
}
// The loop function is called in an endless loop
void loop() {
	// Check for our current button state
	if(changeMode){
		curClickState = checkBtnState();
		switch(curClickState){
		case CLICK_NULL:
			break;
		case CLICK_SINGLE:
			Serial.print("Button Press: CLICK_SINGLE @ ");
			Serial.println(millis());
			changeMode = false;
			writeRGB(255,0,0);
			break;
		case CLICK_LONG:
			Serial.print("Button Press: CLICK_LONG @ ");
			Serial.println(millis());
			changeMode = false;
			writeRGB(0,0,255);
			break;
		}
	}
	delay(10);
}
//The setup function is called once at startup of the sketch
void setup() {

    // Enable the AIN0 comparator interrupt (called with the ISR(ANALOG_COMP_vect) function below)
    ACSR = (0 << ACD)   |  // Analog Comparator Enabled
           (0 << ACBG)  |  // Analog Comparator Bandgap Select: AIN0 is applied to the positive input
           (0 << ACO)   |  // Analog Comparator Output: Off
           (1 << ACI)   |  // Analog Comparator Interrupt Flag: Clear Pending Interrupt
           (1 << ACIE)  |  // Analog Comparator Interrupt: Enabled
           (0 << ACIC)  |  // Analog Comparator Input Capture: Disabled
           (0 << ACIS1) | (0 << ACIS0);   // Analog Comparator Interrupt Mode: Comparator Interrupt on Either Edge

    // Start the AIN0 pin set to input
    pinMode(inputPin,INPUT);

    Serial.begin(115200);
    Serial.println("Starting Arduino...");
    writeRGB(0,0,0);
}
void RGBElement::update()
{
    /*
     * WAIT FOR NEXT WAIT TIME /
     */
    /*
     * IF COLOR CHANGE PRINT STATUS
     */
    if(!isReady())
    {
        if(m_fade)
        {
            fadeColor();
        }
        else
        {
            switchColor();
        }
        writeRGB();
    }
    if(m_sync||(m_play && (millis()> m_nextWait)))
    {
        m_nextWait = millis()+ (m_wTime * 1000);
        stateMaschine();
        if(m_state > 3)
        {
            m_sync = false;
        }
    }
    else if(!m_play)
    {
        /*
         * SAVE WAIT TIME STATE
         *  ADD DURATION QUICKFIX
         */
        if(m_nextWait > millis())
        {
            int diff = m_nextWait - millis();
            m_nextWait += diff;
        }
    }
}
RGBElement::RGBElement(Printer* out, byte R, byte G, byte B, bool invert) :
    m_out(out),
    m_Rport(R),
    m_Gport(G),
    m_Bport(B),
    m_invert(invert)
{

    m_Ract  		= 0;
    m_Gact 			= 0;
    m_Bact 			= 0;

    m_Rnext			= 0;
    m_Gnext			= 0;
    m_Bnext			= 0;

    m_brightness 	= 1;

    m_nextUpdate 	= 0;
    m_uTime			= 5;

    m_nextWait 		= 0;
    m_wTime 		= 60;

    m_play			= true;
    m_sync			= true;
    m_fade			= true;

    m_autoNext 		= true;
    m_ready 		= true;

    m_id 			= 0;
    m_state 		= 0;

    m_colors		= new RGBColorTable(m_out);
    analogWrite(m_Rport, OUTPUT);
    analogWrite(m_Gport, OUTPUT);
    analogWrite(m_Bport, OUTPUT);
    writeRGB();
}