コード例 #1
0
ファイル: main.c プロジェクト: zztbb868/test_D10_WDT
int main (void)
{
	system_init();

  configure_port_pins();

  configure_usart();

  printf("--TEST prepare: ATMEL SAMD10 watchdog callback!\r\n");
  
  configure_wdt();
  configure_wdt_callbacks();  
  
  printf("--TEST prepare: Config WDT:4096 ms!\r\n");
  printf("--TEST prepare: Config WDT:Early Warning,2048ms!\r\n");
  
  system_interrupt_enable_global();

  printf("--TEST prepare: Enable gobale Interrupt!\r\n");
  
  printf("--TEST information: Waitting for WDT Early Warning Interrupt!\r\n");  
  printf("\r\n\r\n\r\n");    

  while(1)
  {
    ;
  }
	/* Insert application code here, after the board has been initialized. */
}
コード例 #2
0
int main(void)
{
	system_init();

	//! [setup_init]
	configure_port_pins();
	//! [setup_init]

	//! [main]
	while (true) {
		//! [main_1]
		bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
		//! [main_1]

		//! [main_2]
		port_pin_set_output_level(LED_0_PIN, !pin_state);
		//! [main_2]
	}
	//! [main]
}
コード例 #3
0
ファイル: main.c プロジェクト: skjeng/cosytech-node
int main (void)
{
	system_init();
	//delay_init();
	configure_port_pins();
	configure_usart();
	
	uint8_t string[] = "Testing usart\n";
	
	usart_write_buffer_wait(&usart_instance, string,sizeof(string));
	port_pin_set_output_level(_RESET, 1);
	port_pin_set_output_level(_RESET, 0);
	delay_ms(100);
	port_pin_set_output_level(_RESET, 1);
	delay_ms(1000);
	
	port_pin_set_output_level(PIN_PA02, !false);
	
	uint8_t ndef_data[] = COSY_DEFAULT_DATA;
	
	rf430_init();
	rf430_write_ndef(ndef_data);
	
	port_pin_set_output_level(PIN_PA02, false);

	// Insert application code here, after the board has been initialized.
	
	//example application with cosytech data. (This data should be fetched from web/bluetooth)
	

	
	while(1){
		delay_ms(500);
		port_pin_set_output_level(PIN_PA02, true);
		delay_ms(500);
		port_pin_set_output_level(PIN_PA02, false);
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: Samatthe/Longboard-Lights
int main (void)
{
	system_init();

	// Initialize local variables used in main
	int failed = 0;
	uint8_t debug_string[24] = "y:     x:     z:   c:   ";
	uint8_t jx, jy;
	char z, c, lz, lc;
	jx = jy = z = c = lz = lc = 0;
	int cycle_index = 0;
	uint8_t cycle = 0;
	uint8_t light_mode = 0; 
	int light_modes = 1;
	uint16_t head, brake = 0;
	uint8_t LIGHTS_ON = 0;
	uint8_t FWD = 0;
	uint8_t HEADLIGHTS = 0;
	uint8_t DEBUG_BLE = 1;
	uint16_t BLE_temp = '0';
	//uint16_t light_sens;

	// Configure Devices
	configure_port_pins();
	configure_LED_PWM();
	configure_usart();
	configure_i2c_slave();
	initIMU();
	failed = !beginIMU();
	configure_i2c_slave_callbacks();
	//configure_ADC();

	// Set the BLE module name to "long-itude"
	uint8_t string[17] = "AT+NAMElong-itude";
	usart_write_buffer_wait(&usart_instance, string, sizeof(string));
	for(int i = 0; i < 50000; ++i);

	// Switch LED direction to FWD
	setFWD();

	while(1)
	{
		//readAccel();
		//readGyro();
		//readMag();
		//light_sens = getLightSens();

		// Read data from BLE
		if (usart_read_wait(&usart_instance, &BLE_temp) == STATUS_OK) {
			switch(BLE_temp)
			{
				case '0':
					LIGHTS_ON = 0;
					break;
				case '1':
					LIGHTS_ON = 1;
					break;
				case '2':
					DEBUG_BLE = 0;
					break;
				case '3':
					DEBUG_BLE = 1;
					break;
				case '4':
					setFWD();
					break;
				case '5':
					setREV();
					break;
			}
		}

		if(DEBUG_BLE)
		{
				uint8_t temp = I2C_slave_read_buffer[0];
				debug_string[4] = '0' + temp%10;
				temp = (temp - temp%10)/10;
				debug_string[3] = '0' + temp%10;
				temp = (temp - temp%10)/10;
				debug_string[2] = '0' + temp%10;
				temp = (temp - temp%10)/10;
				temp = I2C_slave_read_buffer[1];
				debug_string[11] = '0' + temp%10;
				temp = (temp - temp%10)/10;
				debug_string[10] = '0' + temp%10;
				temp = (temp - temp%10)/10;
				debug_string[9] = '0' + temp%10;
				temp = (temp - temp%10)/10;
				debug_string[16] = '0' + I2C_slave_read_buffer[2];
				debug_string[21] = '0' + I2C_slave_read_buffer[3];
				debug_string[22] = '\r';
				debug_string[23] = '\n'; 
				usart_write_buffer_wait(&usart_instance, debug_string, sizeof(debug_string));
		}

		jx = I2C_slave_read_buffer[0];
		jy = I2C_slave_read_buffer[1];
		z = I2C_slave_read_buffer[2];
		c = I2C_slave_read_buffer[3];

		if(z == 0 && lz != 0)
		{
			if(jy > 200)
			{
				setFWD();
				if(HEADLIGHTS && FWD)
					HEADLIGHTS = 0;
				else if(!HEADLIGHTS && FWD)
					HEADLIGHTS = 1;
				else if(HEADLIGHTS && !FWD)
				{
					FWD = 1;
				}
				else if(!HEADLIGHTS && !FWD)
				{
					HEADLIGHTS = 1;
					FWD = 1;
				}
			}
			else if(jy < 55)
			{
				setREV();
				if(HEADLIGHTS && !FWD)
					HEADLIGHTS = 0;
				else if(!HEADLIGHTS && !FWD)
					HEADLIGHTS = 1;
				else if(HEADLIGHTS && FWD)
				{
					FWD = 0;
				}
				else if(!HEADLIGHTS && FWD)
				{
					HEADLIGHTS = 1;
					FWD = 0;
				}
			}
			else if(jy > 110 && jy < 150 && jx > 110 && jx < 150)
			{
				LIGHTS_ON = !LIGHTS_ON;
			}
			else if(jx > 200)
			{
				light_mode++;
				if(light_mode >= light_modes)
					light_mode = 0;
			}
			else if(jx < 55)
			{
				light_mode--;
				if(light_mode <= -1)
					light_mode = light_modes-1;
			}
		}

		if(LIGHTS_ON)
		{
			if(light_mode == 0)
			{
				if(cycle == 0)
				{
					setLeftRGB(cycle_index,0,0xCFFF-cycle_index);
					setRightRGB(cycle_index,0,0xCFFF-cycle_index);
				}
				if(cycle == 1)
				{
					setLeftRGB(0xCFFF-cycle_index,cycle_index,0);
					setRightRGB(0xCFFF-cycle_index,cycle_index,0);
				}
				if(cycle == 2)
				{
					setLeftRGB(0,0xCFFF-cycle_index,cycle_index);
					setRightRGB(0,0xCFFF-cycle_index,cycle_index);
				}

				cycle_index += 250;
				if(cycle_index >= 0xCFFF)
				{
					cycle_index = 0;
					cycle += 1;
					if(cycle == 3)
						cycle = 0;
				}
			}

			if(HEADLIGHTS)
			{
				head = 0xFFFF;
				setWhite(head);
				if(jy < 120)
				{
					brake = (0xFFFF/120)*(120-jy);
					setRed(brake);
				}
				else
					setRed(0);
			}
			else
			{
				setWhite(0);
				setRed(0);
			}
		}
		else
		{
			setWhite(0);
			setRed(0);
			setLeftRGB(0,0,0);
			setRightRGB(0,0,0);
		}

		lc = c;
		lz = z;
	}
}