Exemplo n.º 1
0
int main()
{
	littleWire *myLittleWire = NULL;

	myLittleWire = littleWire_connect();

	if(myLittleWire == NULL){
		printf("Little Wire could not be found!\n");
		exit(EXIT_FAILURE);
	}
	
	version = readFirmwareVersion(myLittleWire);
	printf("Little Wire firmware version: %d.%d\n",((version & 0xF0)>>4),(version&0x0F));	

	pinMode(myLittleWire, BUTTON, INPUT);

	for(;;){
		if ( digitalRead(myLittleWire, BUTTON) == LOW ){
			delay(DEBOUNCE);
			if( digitalRead(myLittleWire, BUTTON) == LOW ){
				printf("Button pressed.\n");
			}
		}
		delay(100);
	}
}
Exemplo n.º 2
0
int main(void)
{
	int step=0;
	
	littleWire *lw = NULL;

	lw = littleWire_connect();

	if(lw == NULL){
		printf("> Little Wire could not be found!\n");
		exit(EXIT_FAILURE);
	}
	
	version = readFirmwareVersion(lw);
	printf("> Little Wire firmware version: %d.%d\n",((version & 0xF0)>>4),(version&0x0F));	
	if(version<0x12)
	{
		printf("> This example requires the new 1.2 version firmware. Please update soon.\n");
		return 0;
	}	
	
	pinMode(lw, LED, OUTPUT);

	for(;;){
		int i=0;
		step++;
		
		for (i=0; i<5; i++)
		{
			switch((i+step)%5) {
				case 0:		ws2812_preload(lw, 255,255,255); break;
				case 1:		ws2812_preload(lw, 255,  0,  0); break;
				case 2:		ws2812_preload(lw, 255,255,  0); break;
				case 3:		ws2812_preload(lw,   0,255,255); break;
				case 4:		ws2812_preload(lw,   0,255,  0); break;				
			}		
		}		
		ws2812_flush(lw, LED);	
		delay(DELAY);
	
		if(lwStatus<0)
		{
			printf("> lwStatus: %d\n",lwStatus);
			printf("> Connection error!\n");
			return 0;
		}
	}
	
}
Exemplo n.º 3
0
int main()
{
	unsigned int chA=0;
	unsigned int chB=0;

	littleWire *myLittleWire = NULL;

	myLittleWire = littleWire_connect();

	if(myLittleWire == NULL){
		printf("Little Wire could not be found!\n");
		exit(EXIT_FAILURE);
	}

	version = readFirmwareVersion(myLittleWire);
	printf("Little Wire firmware version: %d.%d\n",((version & 0xF0)>>4),(version&0x0F));
	
	spi_init(myLittleWire);
	
	// pin3 will be used as our chip select pin
	pinMode(myLittleWire,PIN3,OUTPUT);
	digitalWrite(myLittleWire,PIN3,HIGH);
	
	spi_updateDelay(myLittleWire,0); // Change this according to your device. If your device doesn't respond, try to increase the delay

	unsigned char sendBuffer[4];
	unsigned char receiveBuffer[4];	
	
	for(;;){ // Generates triangular ramp signal
		if(chA<4096) chA++;
		else chA=0;
		if(chB<4096) chB++;
		else chB=0;
		
		sendBuffer[0]=(chA>>4);
		sendBuffer[1]=((chA&0x0F)<<4)+((chB&0xF00)>>8);
		sendBuffer[2]=(chB&0xFF);	
		while(1)
			spi_sendMessage_multiple(myLittleWire,sendBuffer,receiveBuffer,3,AUTO_CS); // Send 3 consequent messages with automatic chip select mode
		delay(2000);
		// Alternative with manual chip select 
		/*
			digitalWrite(myLittleWire,PIN3,LOW); // Chip select low		
				sendSpiMessage_multiple(myLittleWire,sendBuffer,receiveBuffer,3,MANUAL_CS);
			digitalWrite(myLittleWire,PIN3,HIGH); // Chip select high
		*/
	}
}
Exemplo n.º 4
0
int main(void)
{
	littleWire *lw = NULL;

	lw = littleWire_connect();

	if(lw == NULL){
		printf("> Little Wire could not be found!\n");
		exit(EXIT_FAILURE);
	}
	
	version = readFirmwareVersion(lw);
	printf("> Little Wire firmware version: %d.%d\n",((version & 0xF0)>>4),(version&0x0F));	
	if(version<0x12)
	{
		printf("> This example requires the new 1.2 version firmware. Please update soon.\n");
		return 0;
	}	
	
	pinMode(lw, LED, OUTPUT);

	for(;;){
		printf("Red\n");
		ws2812_write(lw, LED, 255,0,0);
		delay(DELAY);
		
		printf("Green\n");
		ws2812_write(lw, LED, 0,255,0);
		delay(DELAY);
		
		printf("Blue\n");
		ws2812_write(lw, LED, 0,0,255);
		delay(DELAY);
		
		printf("Off..\n");
		ws2812_write(lw, LED, 0,0,0);
		delay(DELAY);
	
		if(lwStatus<0)
		{
			printf("> lwStatus: %d\n",lwStatus);
			printf("> Connection error!\n");
			return 0;
		}
	}
	
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
    littleWire *myLittleWire = NULL;
    unsigned int adcValue;

    myLittleWire = littleWire_connect();

    if(myLittleWire == NULL) {
        printf("Little Wire could not be found!\n");
        exit(EXIT_FAILURE);
    }

    version = readFirmwareVersion(myLittleWire);
    printf("Little Wire firmware version: %d.%d\n",((version & 0xF0)>>4),(version&0x0F));

    pinMode(myLittleWire,PIN2,INPUT);

    while(1) {
        adcValue=analogRead(myLittleWire, ADC_PIN2);
        printf("Value: %d\tVoltage: %f volts\n", adcValue,(float)((adcValue*5.0)/1024.0));
        delay(100);
    }
}
Exemplo n.º 6
0
int main()
{
	littleWire *lw = NULL;

	lw = littleWire_connect();

	if(lw == NULL){
		printf("> Little Wire could not be found!\n");
		exit(EXIT_FAILURE);
	}

	version = readFirmwareVersion(lw);
	printf("> Little Wire firmware version: %d.%d\n",((version & 0xF0)>>4),(version&0x0F));	
	if(version==0x10)
	{
		printf("> This example requires the new 1.1 version firmware. Please update soon.\n");
		return 0;
	}
	
	i2c_init(lw);
	i2c_updateDelay(lw,10);

	printf("> Address search ... \n");
	
	for(i=0;i<128;i++)
	{
		rc = i2c_start(lw,i,WRITE);	
		if(rc==1)
			printf("> Found device at %3d\n",i,rc);
	}
	
	delay(2000);
	
	for(;;)
	{ 			
		/* Fade to a HSV color */
		i2c_start(lw,0x09,WRITE);						
			myBuffer[0] = 'h';
			myBuffer[1] = i++;
			myBuffer[2] = 255;
			myBuffer[3] = 255;		
		i2c_write(lw,myBuffer,4,END_WITH_STOP);
		
		delay(10);
		
		/* Get the current RGB color values */				
		i2c_start(lw,0x09,WRITE);		
			myBuffer[0] = 'g'; 
		i2c_write(lw,myBuffer,1,END_WITH_STOP);
		
		delay(10);
		
		/* Actually read the three bytes */
		i2c_start(lw,0x09,READ);
		i2c_read(lw,myBuffer,3,END_WITH_STOP);
		
		delay(10);		
		
		printf("> Read:\t#R: %2X\t#G: %2X\t#B: %2X\t\n",myBuffer[0],myBuffer[1],myBuffer[2]);				
		
		if(lwStatus<0)
		{
			printf("> lwStatus: %d\n",lwStatus);
			printf("> Connection error!\n");
			return 0;
		}
	}
	
	return 0;
}
Exemplo n.º 7
0
int main(void)
{
	littleWire *lw = NULL;
	
	total_lwCount = littlewire_search();

	if(total_lwCount == 1)
	{
		printf("----------------------------------------------------------\n");
		printf("> 1 Little Wire device is found with serialNumber: %d\n",lwResults[0].serialNumber);
		printf("----------------------------------------------------------\n");
	}
	else if(total_lwCount > 1)
	{
		printf("----------------------------------------------------------\n");
		printf("> %d Little Wire devices are found\n",total_lwCount);
		printf("----------------------------------------------------------\n");
		printf("> #id - serialNumber\n");
		for(i=0;i<total_lwCount;i++)
		{
			printf(">  %2d - %3d\n",i,lwResults[i].serialNumber);
		}
		printf("----------------------------------------------------------\n");
	}
	else if(total_lwCount == 0)
	{
		printf("----------------------------------------------------------\n");
		printf("> Little Wire could not be found!\n");
		printf("----------------------------------------------------------\n");
		exit(EXIT_FAILURE);
	}	

	/* Connects to the first littleWire device the computer can find. */
	// lw = littleWire_connect();

	/* Connects to the spesific littleWire device by array id. */
	lw = littlewire_connect_byID(0);

	/* Connects to the spesific littleWire with a given serial number. */
	/* If multiple devices have the same serial number, it connects to the last one it finds */
	// lw = littlewire_connect_bySerialNum(126);

	if(lw == NULL){
		printf("> Little Wire connection problem!\n");
		exit(EXIT_FAILURE);
	}
	
	version = readFirmwareVersion(lw);
	printf("> Little Wire firmware version: %d.%d\n",((version & 0xF0)>>4),(version&0x0F));	
	if(version < 0x12)
	{
		printf("> This example requires the new 1.2 version firmware. Please update soon.\n");
		return 0;
	}	

	/* In order to change the serial number of the current connected device, use the following function. */
	/* You need to unplug-plug to see the change. */
	/* Serial numbers have to be between 100-999 */
	// changeSerialNumber(lw,152);

	/*------------------------------------------------------------------------------------------------------*/

	pinMode(lw, LED, OUTPUT);

	printf("Switching relay...\n");
	digitalWrite(lw, LED, HIGH);
	delay(DELAY);
	digitalWrite(lw, LED, LOW);
	printf("...done!\n");
	
	if(lwStatus<0)
	{
		printf("> lwStatus: %d\n",lwStatus);
		printf("> Connection error: ");
		printf("%s\n",littleWire_errorName());
	}
	
	return 0;
}