Exemplo n.º 1
0
//------------------------------------------------------------------------------
// Initializes everything needed to use this library. This clears the strip.
void initStrip()
{
// initialize eUSCI
	UCB1CTLW0 = 0x0001;                   // hold the eUSCI module in reset mode
	  // configure UCA3CTLW0 for:
	  // bit15      UCCKPH = 1; data shifts in on first edge, out on following edge
	  // bit14      UCCKPL = 0; clock is low when inactive
	  // bit13      UCMSB = 1; MSB first
	  // bit12      UC7BIT = 0; 8-bit data
	  // bit11      UCMST = 1; master mode
	  // bits10-9   UCMODEx = 2; UCSTE active low
	  // bit8       UCSYNC = 1; synchronous mode
	  // bits7-6    UCSSELx = 2; eUSCI clock SMCLK
	  // bits5-2    reserved
	  // bit1       UCSTEM = 1; UCSTE pin enables slave
	  // bit0       UCSWRST = 1; reset enabled
	UCB1CTLW0 = 0xAD83;
	  // set the baud rate for the eUSCI which gets its clock from SMCLK
//	  UCA3BRW = 3; // 16 MHz / 3 = .1875 us per bit
	UCB1BRW = 3; // 12 MHz / 6 = .25 us per bit
	  // modulation is not used in SPI mode, so clear UCA3MCTLW
//	UCB1MCTLW = 0;
	P6SEL0 |= 0x38;
	P6SEL1 &= ~0x38;                      // configure P9.7, P9.5, and P9.4 as primary module function
	UCB1CTLW0 &= ~0x0001;                 // enable eUSCI module
	UCB1IE &= ~0x0003;                    // disable interrupts

//	spi_Open();


	clearStrip();					// clear the strip
}
Exemplo n.º 2
0
int 	main(void) {
	//init_ports();
	//init_spi();
	//init_uart();

	DDRB = 0xFF;
	PORTB = 0xFF;
	DDRC	= 0x00;
	DIDR0	= 0xFF;
	DDRD 	= 0b11111011;	// PD2 as button input, PD0 as UART RX
	PORTD = 0;

	init_spi();

/*	for ( ; ; ){
		//PORTB = 0xFF;
		//PORTB = 0;
		hardware_spi_write(0xF0);
	}
*/

	clearStrip(nullstrip, NUM_LEDS);

	clearStrip(strip, NUM_LEDS);
	writeStrip(strip, NUM_LEDS, hardware_spi_write);
	latchStrip(hardware_spi_write, NUM_LEDS);

/*	uint8_t	stripAddress = 0x00;

	uint8_t	serial_inBuffer[SERIAL_INBUFFER_LEN];
	uint8_t	serial_inPos = 0;
	uint8_t	serial_rxState = 0;
	uint8_t	serial_mask = 0;
	uint8_t serial_packetLen = 0; */

//	init_adc();
//	uint8_t offset = 0;

	uint16_t	buttonTimer = 0;
	uint16_t	resetTimer = 0;
	uint8_t 	displayState = 0;

	for ( ; ; ) {
	/*	if (PORTD & BUTTONMASK) { // Button is pressed
			buttonTimer++;
			resetTimer = 0;
		} else {	// Button is not pressed
			if (buttonTimer > 1000) // holding the button
				displayState = 0;
			else if (buttonTimer > 30) // quick press
				displayState++;
			buttonTimer = 0;
		}  */

		if ((PIND & BUTTONMASK)==0) {
			if (buttonTimer == 0) displayState++;
			buttonTimer = 1;
		} else {
			buttonTimer = 0;
		}

		switch (displayState) {
			case 0:
				effect_colorFade(strip, 100, 32);
				break;
			case 1:
				effect_colorFade(strip, 10, 32);
				break;
			case 2:
				effect_rgbChecker(strip, NUM_LEDS, 32);
				writeStrip(strip, NUM_LEDS, hardware_spi_write);
				latchStrip(hardware_spi_write, NUM_LEDS);
				_delay_ms(300);
				break;
			case 3:
				effect_colorStrobe(strip, NUM_LEDS, 20, 20, 32);
				break;
			case 4:
				effect_rgbStrobe(strip, NUM_LEDS, 20, 20, 32, 3);
				break;
			default:
				displayState = 0;
				break;
		}

	}

	/*	uint8_t j;
		for (j=0; j<3; j++) {
			ADMUX = (j | 0xC0);	// Red on AN0, Green on AN1, Blue on AN2
			ADC_START();
			//_delay_ms(10);
			loop_until_bit_is_clear(ADCSRA, ADSC);
			uint16_t newsample = ADCL;
			newsample += (ADCH << 8);
			switch (j) {
				case 0:	// Red
					r = newsample >> 4;// * 10;
					break;
				case 1:	// Green
					g = newsample >> 3;// * 14;
					break;
				case 2:	// Blue
					b = newsample >> 3;// * 17;
					break;
			}
		}

		setStripColor(strip, NUM_LEDS, r, g, b); */
		//effect_rgbChecker(strip, NUM_LEDS, 32);
		//effect_colorFade(strip, 10, 32);
		effect_rgbStrobe(strip, NUM_LEDS, 10, 20, 40, 5);
		//if (offset >= 3) offset = 0;

		//_delay_ms(50);

	/*	clearStrip(strip, NUM_LEDS);
		writeStrip(strip, NUM_LEDS, hardware_spi_write);
		latchStrip(hardware_spi_write, NUM_LEDS);
		_delay_ms(500);

		if (offset == 3) offset = 0;  */

	


/*	for ( ; ; ) {
		if (checkflag(SERIAL_FLAG)) {
			switch (serial_rxState) {
				case RX_State_first_byte:
					serial_packetLen = 0;
					serial_inPos = 0;
					if (serial_in < 128) {	// Strip address
						if (stripAddress == serial_in)
							serial_rxState = RX_State_packet_len;
						else
							serial_rxState = RX_State_packet_len_skip;
					}	else {
						serial_mask = (serial_in & 0x7F);
						serial_rxState = RX_State_mask_match;
					}
					break;
				
				case RX_State_packet_len:
					serial_packetLen = serial_in;
					serial_rxState = RX_State_payload;
					break;

				case RX_State_packet_len_skip:
					serial_packetLen = serial_in;
					serial_rxState = RX_State_skip;
					break;

				case RX_State_mask_match:
					if (serial_in == (serial_mask & stripAddress))
						serial_rxState = RX_State_packet_len;
					else
						serial_rxState = RX_State_packet_len_skip;
					break;

				case RX_State_payload:
					serial_inBuffer[serial_inPos++] = serial_in;
					if (serial_inPos == serial_packetLen) {
						// process packet
						serial_processPacket(serial_inBuffer, strip, NUM_LEDS);
						serial_rxState = RX_State_first_byte;
					}
					else if (serial_inPos == SERIAL_INBUFFER_LEN)
						serial_inPos = 0;
					break;

				case RX_State_skip:
					serial_inPos++;
					if (serial_inPos == serial_packetLen)
						serial_rxState = RX_State_first_byte;
					break;

			}
		}
	}
*/

/*	for ( ; ; ){
		//	Main code here

		effect_rgbChecker(strip, NUM_LEDS, offset++);
		writeStrip(strip, NUM_LEDS, hardware_spi_write);
		latchStrip(hardware_spi_write, NUM_LEDS);
		_delay_ms(50);
		if (offset == 3) offset = 0;

 	} */
}