Ejemplo n.º 1
0
void Wakeup::set(uint8 r, uint8 g, uint8 b) {
  sendBlankFrame();
  sendColor(r, g, b);
  sendColor(r, g, b);
  sendColor(r, g, b);
  sendBlankFrame(); 
}
Ejemplo n.º 2
0
void TclClass::setAll(int num_leds, byte red, byte green, byte blue) {
  sendEmptyFrame();
  for (int i=0; i<num_leds; i++) {
    sendColor(red, green, blue);
  }
  sendEmptyFrame();
}
Ejemplo n.º 3
0
void ChainableLED::setColorRGB(byte led, byte red, byte green, byte blue)
{
    // Send data frame prefix (32x "0")
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
    
    // Send color data for each one of the leds
    for (byte i=0; i<_num_leds; i++)
    {
        if (i == led)
        {
            _led_state[i*3 + _CL_RED] = red;
            _led_state[i*3 + _CL_GREEN] = green;
            _led_state[i*3 + _CL_BLUE] = blue;
        }
                    
        sendColor(_led_state[i*3 + _CL_RED], 
                  _led_state[i*3 + _CL_GREEN], 
                  _led_state[i*3 + _CL_BLUE]);
    }

    // Terminate data frame (32x "0")
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
}
Ejemplo n.º 4
0
void ColorChooser::on_currentColorChanged(const QColor &color)
{
    if (!color.isValid())
        return;

    currentColor = color;
    update();

    emit(sendColor(color));
}
Ejemplo n.º 5
0
void ColorChooser::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        QColor color = QColorDialog::getColor(*mCurrentColor, this);
        if(color.isValid())
        {
            setColor(color);
            emit sendColor(key, color);
        }
    }
}
Ejemplo n.º 6
0
void RGBLED::setColorRGB(byte red, byte green, byte blue)
{
    // Send data frame prefix (32x "0")
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
    
    sendColor(red,green,blue);

    // Terminate data frame (32x "0")
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
    sendByte(0x00);
}
Ejemplo n.º 7
0
void tileSetup(void){
	//Initialization routines
	initIO();
	setPort(&PORTB);
	sendColor(LEDCLK,LEDDAT,dark);
	sei();
	initAD();
	initTimer();
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	//Set up timing ring buffers
	uint8_t i;
	for(i = 0; i<6; i++){
		timeBuf[i]=0;
	}
	mode = running;
}
Ejemplo n.º 8
0
void MainWindow::initializeNewTab(const bool &isOpen, const QString &filePath)
{
    ImageArea *imageArea;
    QString fileName(tr("Untitled Image"));
    if(isOpen && filePath.isEmpty())
    {
        imageArea = new ImageArea(isOpen, "", this);
        fileName = imageArea->getFileName();
    }
    else if(isOpen && !filePath.isEmpty())
    {
        imageArea = new ImageArea(isOpen, filePath, this);
        fileName = imageArea->getFileName();
    }
    else
    {
        imageArea = new ImageArea(false, "", this);
    }
    if (!imageArea->getFileName().isNull())
    {
        QScrollArea *scrollArea = new QScrollArea();
        scrollArea->setAttribute(Qt::WA_DeleteOnClose);
        scrollArea->setBackgroundRole(QPalette::Dark);
        scrollArea->setWidget(imageArea);

        mTabWidget->addTab(scrollArea, fileName);
        mTabWidget->setCurrentIndex(mTabWidget->count()-1);

        mUndoStackGroup->addStack(imageArea->getUndoStack());
        connect(imageArea, SIGNAL(sendPrimaryColorView()), mToolbar, SLOT(setPrimaryColorView()));
        connect(imageArea, SIGNAL(sendSecondaryColorView()), mToolbar, SLOT(setSecondaryColorView()));
        connect(imageArea, SIGNAL(sendRestorePreviousInstrument()), this, SLOT(restorePreviousInstrument()));
        connect(imageArea, SIGNAL(sendSetInstrument(InstrumentsEnum)), this, SLOT(setInstrument(InstrumentsEnum)));
        connect(imageArea, SIGNAL(sendNewImageSize(QSize)), this, SLOT(setNewSizeToSizeLabel(QSize)));
        connect(imageArea, SIGNAL(sendCursorPos(QPoint)), this, SLOT(setNewPosToPosLabel(QPoint)));
        connect(imageArea, SIGNAL(sendColor(QColor)), this, SLOT(setCurrentPipetteColor(QColor)));
        connect(imageArea, SIGNAL(sendEnableCopyCutActions(bool)), this, SLOT(enableCopyCutActions(bool)));
        connect(imageArea, SIGNAL(sendEnableSelectionInstrument(bool)), this, SLOT(instumentsAct(bool)));

        setWindowTitle(QString("%1 - EasyPaint").arg(fileName));
    }
Ejemplo n.º 9
0
void ToolBar::initializeItems()
{
    mCursorButton = createToolButton(mActMap[CURSOR]);
    mEraserButton = createToolButton(mActMap[ERASER]);
    mPenButton = createToolButton(mActMap[PEN]);
    mLineButton = createToolButton(mActMap[LINE]);
    mColorPickerButton = createToolButton(mActMap[COLORPICKER]);
    mMagnifierButton = createToolButton(mActMap[MAGNIFIER]);
    mSprayButton = createToolButton(mActMap[SPRAY]);
    mFillButton = createToolButton(mActMap[FILL]);
    mRectangleButton = createToolButton(mActMap[RECTANGLE]);
    mEllipseButton = createToolButton(mActMap[ELLIPSE]);
    mCurveButton = createToolButton(mActMap[CURVELINE]);
    mTextButton = createToolButton(mActMap[TEXT]);

    QGridLayout *bLayout = new QGridLayout();
    bLayout->setMargin(3);
    bLayout->addWidget(mCursorButton, 0, 0);
    bLayout->addWidget(mEraserButton, 0, 1);
    bLayout->addWidget(mColorPickerButton, 1, 0);
    bLayout->addWidget(mMagnifierButton, 1, 1);
    bLayout->addWidget(mPenButton, 2, 0);
    bLayout->addWidget(mLineButton, 2, 1);
    bLayout->addWidget(mSprayButton, 3, 0);
    bLayout->addWidget(mFillButton, 3, 1);
    bLayout->addWidget(mRectangleButton, 4, 0);
    bLayout->addWidget(mEllipseButton, 4, 1);
    bLayout->addWidget(mCurveButton, 5, 0);
    bLayout->addWidget(mTextButton, 5, 1);

    QWidget *bWidget = new QWidget();
    bWidget->setLayout(bLayout);

    mPColorChooser = new ColorChooser(0, 0, 0, this);
    mPColorChooser->setStatusTip(tr("Primary color"));
    mPColorChooser->setToolTip(tr("Primary color"));
    connect(mPColorChooser, SIGNAL(sendColor(QColor)), this, SLOT(primaryColorChanged(QColor)));
    connect(mPColorChooser, SIGNAL(colorDialogClosed()), this, SIGNAL(colorDialogClosed()));

    mSColorChooser = new ColorChooser(255, 255, 255, this);
    mSColorChooser->setStatusTip(tr("Secondary color"));
    mSColorChooser->setToolTip(tr("Secondary color"));
    connect(mSColorChooser, SIGNAL(sendColor(QColor)), this, SLOT(secondaryColorChanged(QColor)));
    connect(mSColorChooser, SIGNAL(colorDialogClosed()), this, SIGNAL(colorDialogClosed()));

    QSpinBox *penSizeSpin = new QSpinBox();
    penSizeSpin->setRange(1, 20);
    penSizeSpin->setValue(1);
    penSizeSpin->setStatusTip(tr("Pen size"));
    penSizeSpin->setToolTip(tr("Pen size"));
    connect(penSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(penValueChanged(int)));

    QGridLayout *tLayout = new QGridLayout();
    tLayout->setMargin(3);
    tLayout->addWidget(mPColorChooser, 0, 0);
    tLayout->addWidget(mSColorChooser, 0, 1);
    tLayout->addWidget(penSizeSpin, 1, 0, 1, 2);

    QWidget *tWidget = new QWidget();
    tWidget->setLayout(tLayout);

    addWidget(bWidget);
    addSeparator();
    addWidget(tWidget);
}
Ejemplo n.º 10
0
void main(void){

	
	int sum,average,level,level_last,count;
   char interval =0;
   int max_timeout ;
   float ratio;
   int r,g,b;
   int lights;
	int peak[5];
   int peak_last[5];
   int avg[5];
   int max[5];
	int filt_out[5];
   int color[5];
	int i,j;
	int bytes_read;
   int temp_val;
	bytes_read = BUFFER_SIZE;
   setvbuf(stdout, NULL, _IONBF, 0);
	printf("Hello World!\n");
   SERIAL = fopen("/dev/ttyO1","w");
   setvbuf(SERIAL, NULL, _IONBF, 0);
   
   kiss_fftr_state = kiss_fftr_alloc(BUFFER_SIZE,0,0,0);
   
   sendColor(4,255,0,0,0);
   sendColor(9,0,255,0,0);
	color[0] = max[0] = avg[0] = 0;
	color[1] = max[1] =avg[1] = 0;
	color[2] = max[2] =avg[2] = 0;
	color[3] = max[3] =avg[3] = 0;
	color[4] = max[4] =avg[4] = 0;
	
   interval =0;
   max_timeout = 50;
	while(bytes_read==BUFFER_SIZE){
      // bytes_read = fread(&audio_data,sizeof(short),512,stdin);
      bytes_read = fread(&audio_data,sizeof(short),BUFFER_SIZE,stdin);
   
      for(i = 0; i< BUFFER_SIZE;i++){
         rin[i] = (audio_data[i]*hamming_window512[i])/16384;
      }
		
      
      
     
    
		
		// for(i = 0;i<bytes_read; i++){
		//        //sum +=audio_data[i];
		//        filt_out[0] = calculate_FIR(&filter0,audio_data[i]);
		//        filt_out[1] = calculate_FIR(&filter1,audio_data[i]);
		//        filt_out[2] = calculate_FIR(&filter2,audio_data[i]);
		//        filt_out[3] = calculate_FIR(&filter3,audio_data[i]);
		//        filt_out[4] = calculate_FIR(&filter4,audio_data[i]);
		//        for(j=0;j<5;j++){
		//        filt_out[j] = abs(filt_out[j]);
		//        peak[j] = (filt_out[j] > peak[j])? filt_out[j]: peak[j];
		//        }
		// 
		//     }
		if(interval == 0){
		   kiss_fftr( kiss_fftr_state, rin, sout );
		   for(lights = 0;lights<NUM_LIGHTS; lights++){
            sum = 0;
            count = 0;
            for(i = band_min[lights];i<=band_max[lights];i++){
               sum += sqrt(sout[i].r*sout[i].r + sout[i].i*sout[i].i);
               count ++;
            }
            peak[lights] = sum/ count ;
            avg[lights] = calculate_average(&(averages[lights]),peak[lights]);
         }
      
         for(j=0;j<NUM_LIGHTS;j++){
            if(peak[j]>max[j]){
                 max[j] = peak[j];
            }
                 ratio =(avg[j])? ((float)peak[j])/avg[j]:0;
                 level =(int)(threshold[j]*ratio);
                 if(level > 12) level = 12;
                 
                 ratio =(avg[j])? ((float)peak_last[j])/avg[j]:0;
                 level_last =(int)(threshold[j]*ratio);
                 if(level_last > 12) level_last = 12;
                 
                 
                 if(level <1 && level_last >1){
                    color[j] ++;
                    color[j] %=12;
                 }
                 peak_last[j] = peak[j];
                 
                 level = (max[j])? (12*peak[j])/max[j]:0;
                 printf("%d:%8d ",level,avg[j]);
                 r = color_array[12-level][color_order[color[j]]][0];
                 g = color_array[12-level][color_order[color[j]]][1];
                 b = color_array[12-level][color_order[color[j]]][2];
                 // if(level>1){
                  sendColor(address_table[j],r,g,b,0);
                 // }else{
                 //   sendColor(address_table[j],0,0,0,0);
                 // }
              //sendColor(9,0,255,0,0);
                 if(max_timeout == 0){
                    printf("Avg[%d]=%d ",j,avg[j]);
                    max[j]= (max[j]/4 > avg[j])? max[j]-(max[j]-avg[j])/2: max[j];
                    
                 }
         }
         printf ("\n");
         
         if(max_timeout == 0){
            max_timeout = 300;
         }
         max_timeout --;
      }
           
      interval ++;
      interval %=2;
      


		//printf("%8d:%8d:%8d:%8d:%8d\n", peak[0],peak[1],peak[2],peak[3],peak[4]);
		//printf("%d,%d,%d,%d,%d\n", peak[0],peak[1],peak[2],peak[3],peak[4]);
	}
	free(kiss_fftr_state);
}
Ejemplo n.º 11
0
void Face::sendValues()
{
    sendColor();
    sendIntensity();
}
Ejemplo n.º 12
0
// Finally, the actual calls to do something with all this data.  You can either choose to render
// it given the configuration, or generate a display list of rendering it with the given
// configuration (uses GL_COMPILE mode to build the list).  Fails if insufficient data has
// been given (i.e. if you don't give it an array for an enabled parameter, if you don't
// give it an array of indices when it needs them).
// Note that rendering with GLVERTEX_MODE currently involves a lot of CPU overhead to
// unpack the data and pass it to the GL; while the results will be correct, it would be
// unwise to use this method for rendering that is to be benchmarked, because it will
// underestimate performance significantly on some machines.
bool GeomRenderer::renderPrimitives(GLenum mode)
{
    if (!isReadyToRender())
    {
        return false;
    }

    // Okay, different sections here depending on what we're doing.
    if (drawMethod == GLVERTEX_MODE)
    {
        glBegin(mode);
        for (unsigned int x=0; x<indicesCount; x++)
        {
            int directIndex = getIndex(x);
            if (parameterBits & COLOR_BIT) sendColor(directIndex);
            if (parameterBits & TEXTURE_COORD_BIT) sendTexCoord(directIndex);
            if (parameterBits & NORMAL_BIT) sendNormal(directIndex);
            sendVertex(directIndex);
        }
        glEnd();
    }
    // Otherwise it has something to do with arrays; set up the arrays.
    else
    {
        if (parameterBits & COLOR_BIT)
        { 
            glEnableClientState(GL_COLOR_ARRAY);
            glColorPointer(colorData.size, colorData.type, colorData.stride, colorData.pointer);
//            std::cout << "Enabled color arrays, size [" << colorData.size << "], type [" << colorData.type 
//                      << "], stride [" << colorData.stride << "], pointer [" << colorData.pointer << "]" << std::endl;
        }
        if (parameterBits & TEXTURE_COORD_BIT)
        { 
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(texCoordData.size, texCoordData.type, texCoordData.stride, texCoordData.pointer);
//            std::cout << "Enabled texCoord arrays, size [" << texCoordData.size << "], type [" << texCoordData.type 
//                      << "], stride [" << texCoordData.stride << "], pointer [" << texCoordData.pointer << "]" << std::endl;
        }
        if (parameterBits & NORMAL_BIT)
        { 
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(normalData.type, normalData.stride, normalData.pointer);
//            std::cout << "Enabled normal arrays, size [" << normalData.size << "], type [" << normalData.type 
//                      << "], stride [" << normalData.stride << "], pointer [" << normalData.pointer << "]" << std::endl;
        }
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(vertexData.size, vertexData.type, vertexData.stride, vertexData.pointer);
//        std::cout << "Enabled vertex arrays, size [" << vertexData.size << "], type [" << vertexData.type 
//                  << "], stride [" << vertexData.stride << "], pointer [" << vertexData.pointer << "]" << std::endl;

        // Should we lock?
        if (compileArrays)
        {
            assert(GLUtils::haveExtension("GL_EXT_compiled_vertex_array"));
            glLockArraysEXT(0, arrayLength);
        }

        // Okay, arrays configured; what exactly are we doing?
        if (drawMethod == GLARRAYELEMENT_MODE)
        {
            glBegin(mode);
            for (unsigned int x=0; x<indicesCount; x++)
            {
                glArrayElement(getIndex(x));
            }
            glEnd();
        }
        else if (drawMethod == GLDRAWARRAYS_MODE)
        {
            glDrawArrays(mode, 0, arrayLength);
            std::cout << "Called glDrawArrays, mode [" << mode << "], from 0 to " << arrayLength << std::endl;
        }
        else if (drawMethod == GLDRAWELEMENTS_MODE)
        {
            glDrawElements(mode, indicesCount, indicesType, indices);
        }

        // Done.  If we locked, unlock.
        if (compileArrays)
        {
            assert(GLUtils::haveExtension("GL_EXT_compiled_vertex_array"));
            glUnlockArraysEXT();
        }
    }

    return true;
}
Ejemplo n.º 13
0
void main(void){

	
	int sum,average,level;
   int r,g,b;
	int peak[5];
   int max[5];
	int filt_out[5];
   int color[5];
	int i,j;
	int bytes_read;
   int temp_val;
	bytes_read = BUFFER_SIZE;
   setvbuf(stdout, NULL, _IONBF, 0);
	printf("Hello World!\n");
   SERIAL = fopen("/dev/ttyO1","w");
   setvbuf(SERIAL, NULL, _IONBF, 0);
   
   kiss_fftr_state = kiss_fftr_alloc(BUFFER_SIZE,0,0,0);
   
   sendColor(4,255,0,0,0);
   sendColor(9,0,255,0,0);
	color[0] = max[0] = 0;
	color[1] = max[1] = 0;
	color[2] = max[2] = 0;
	color[3] = max[3] = 0;
	color[4] = max[4] = 0;
	while(bytes_read==BUFFER_SIZE){
      // bytes_read = fread(&audio_data,sizeof(short),512,stdin);
      bytes_read = fread(&rin,sizeof(short),512,stdin);
		sum = 0;
		average = 0;
		peak[0] = 0;
		peak[1] = 0;
		peak[2] = 0;
		peak[3] = 0;
		peak[4] = 0;
		kiss_fftr( kiss_fftr_state, rin, sout );
		
      for(i =0; i< BUFFER_SIZE/2; i+=2){
         temp_val = sout[i].r +sout[i+1].r;
         printf("%8d ",temp_val);
      }
      printf("\n");
		
		
		// for(i = 0;i<bytes_read; i++){
		//        //sum +=audio_data[i];
		//        filt_out[0] = calculate_FIR(&filter0,audio_data[i]);
		//        filt_out[1] = calculate_FIR(&filter1,audio_data[i]);
		//        filt_out[2] = calculate_FIR(&filter2,audio_data[i]);
		//        filt_out[3] = calculate_FIR(&filter3,audio_data[i]);
		//        filt_out[4] = calculate_FIR(&filter4,audio_data[i]);
		//        for(j=0;j<5;j++){
		//        filt_out[j] = abs(filt_out[j]);
		//        peak[j] = (filt_out[j] > peak[j])? filt_out[j]: peak[j];
		//        }
		// 
		//     }
	   // for(j=0;j<5;j++){
	  //       if(peak[j]>max[j]){
	  //             max[j] = peak[j];
	  //       }
	  //          level = (12*peak[j])/max[j];
	  //          if(level >=10){
	  //             color[j] ++;
	  //             color[j] %=10;
	  //          }
	  //          printf("%8d:%8d ",level,max[j]);
	  //          r = color_array[12-level][color_order[color[j]]][0];
	  //          g = color_array[12-level][color_order[color[j]]][1];
	  //          b = color_array[12-level][color_order[color[j]]][2];
	  //       sendColor(address_table[j],r,g,b,0);
	  //       //sendColor(9,0,255,0,0);
	  //       }
	  //       printf ("\n");
		/*
		for(j=0;j<5;j++){
		intensity[j] = log10_10 * peak[j];
		}*/
		//printf("%8d:%8d:%8d:%8d:%8d\n", peak[0],peak[1],peak[2],peak[3],peak[4]);
		//printf("%d,%d,%d,%d,%d\n", peak[0],peak[1],peak[2],peak[3],peak[4]);
	}
	free(kiss_fftr_state);
}
Ejemplo n.º 14
0
int main(void)
{
	//Initialization routines
	initIO();
	setPort(&PORTB);
	sendColor(LEDCLK,LEDDAT,colors[0]);
	sei();
	initAD();
	initTimer();
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	//Set up timing ring buffers
	for(uint8_t i = 0; i<6; i++){
		timeBuf[i]=0;
	}
	
	mode = running;
	
    while(1)

    {	
		if(mode==sleep){
			disAD();
			//
			DDRB &= ~IR;//Set direction in
			PORTB &= ~IR;//Set pin tristated
			sendColor(LEDCLK, LEDDAT, dark);
			PORTA |= POWER;//Set LED and Mic power pin high (off)
			wake = 0;
			while(!wake){
				cli();
				uint32_t diff = timer-powerDownTimer;
				sei();
				if(diff>500){
					sleep_cpu();
					wake = 1;
				}
			}
			holdoff=500;
			PORTA &= ~POWER;
			
			uint8_t done = 0;
			cli();
			uint32_t startTime = timer;
			sei();
			while(!done){
				cli();
				uint32_t time = timer;
				sei();
				if(time-startTime>250){
					done=1;
				}
			}
			
			done = 0;
			cli();
			startTime = timer;
			sei();
			DDRB |= IR;//Set direction out
			PORTB |= IR;//Set pin on
			sendColor(LEDCLK, LEDDAT, transmitColor);
			while(!done){
				cli();
				uint32_t time = timer;
				sei();
				if(time-startTime>500){
					done=1;					
				}				
			}
			enAD();
			powerDownTimer = timer;
			sleepTimer = timer;
			mode = running;
		}else if(mode==running){
			if(click){
				uint8_t neighborStates[6];
				getStates(neighborStates);
				uint8_t clickColor[] = {bright(colors[state][0]),bright(colors[state][1]),bright(colors[state][2])}; 
				sendColor(LEDCLK, LEDDAT, clickColor);
				uint8_t numOn = 0;

				sync = 3;//request sync pulse be sent at next possible opportunity (set to 4 for logistical reasons)

				for (uint8_t i = 0; i< 6; i++)
				{
					//at the moments specific state detection is a bit iffy, 
					//so mapping any received state>1 to a state of 1 works for now
					if(neighborStates[i]>0){
						numOn++;
					}	
				}
				//Logic for what to do to the state based on number of on neighbors
				if(state == 0) {
					if(birthRules[numOn]) {
						state=1;
					}
				}
				else {
					if(deathRules[numOn]) {
						state = (state + 1) % numStates;
					}
				}
				//End logic

				//prevent another click from being detected for a bit
				holdoff = 100;
				click = 0;
			}
		
			//periodically update LED once every 0x3F = 64 ms (fast enough to feel responsive)
			cli();
			if(!(timer & 0x3F)){
				if(timer!=lastTime){
					lastTime=timer;
					cycleTimer++;
					cycleTimer %= CYCLE_TIME;
					uint8_t outColor[3] = {(colors[state][0]*breatheCycle[cycleTimer])/255, 
										   (colors[state][1]*breatheCycle[cycleTimer])/255,
										   (colors[state][2]*breatheCycle[cycleTimer])/255};
					sendColor(LEDCLK, LEDDAT, outColor);
				}
			}
			sei();
			//check if we enter sleep mode
			cli();//temporarilly prevent interrupts to protect timer
			if(timer-sleepTimer>1000*TIMEOUT){
				mode = sleep;
			}
			sei();
		}else if(mode==recieving){
			//disable A/D
			disAD();
			//set photo transistor interrupt to only trigger on specific direction
			setDir(progDir);
			//set recieving color
			sendColor(LEDCLK, LEDDAT, recieveColor);	
			//record time entering the mode for timeout
			cli();
			uint32_t modeStart = timer;
			sei();
			while(mode==recieving){//stay in this mode until instructed to leave or timeout
				cli();
				uint32_t diff = timer-modeStart;
				sei();
				if(diff>3000){//been in mode 1 for more than 5 seconds
					mode = transmitting;					
				}
			}
		}else if(mode==transmitting){
			//disable Phototransistor Interrupt
			setDirNone();
			//set LED to output
			DDRB |= IR;//Set direction out
			//send 5 pulses
			uint32_t startTime = timer;
			if(bitsRcvd>=8 && comBuf[0]!=seqNum){
				for(int i=0; i<5; i++){
					while(timer==startTime){
						PORTB &= ~IR;
					}
					startTime = timer;
					while(timer==startTime){
						PORTB |= IR;
					}
					startTime = timer;
				}
				parseBuffer();
			}else{
				bitsRcvd = 0;
			}
			
			startTime = timer;
			sendColor(LEDCLK, LEDDAT, transmitColor);//update color while waiting			
			while(timer<startTime+20);//pause for mode change
			startTime = timer;
			uint16_t timeDiff;
			uint16_t bitNum;
			while(bitsRcvd>0){
				timeDiff = (timer-startTime)/PULSE_WIDTH;
				bitNum = timeDiff/2;
				if(timeDiff%2==0){//first half
					if(comBuf[bitNum/8]&(1<<bitNum%8)){//bit high
						PORTB &=  ~IR;
					}else{//bit low
						PORTB |=  IR;
					}
				}else{//second half
					if(comBuf[bitNum/8]&(1<<bitNum%8)){//bit high
						PORTB |=  IR;
						}else{//bit low
						PORTB &=  ~IR;
					}
				}
				if(bitNum>=bitsRcvd){
					bitsRcvd = 0;
				}				
			}
			//while(timer<startTime+2000);//pause for effect
			
			//done transmitting
			//re-enable A/D
			enAD();
			//re-enable all phototransistors
			setDirAll();
			state = 0;
			mode = running;

		}
	}
}