예제 #1
0
int main(void) {
    const unsigned short MainCycle = 60;
    Init(MainCycle);

    for (;;) {
        step();
        if (is_black() == 0){
        	LED(3);
        }else if((is_black_left() == 1) && (is_black_right() == 0)){
            turn_left();
            LED(2);
        }else if((is_black_left() == 0) && (is_black_right() == 1)){
        	turn_right();
        	LED(1);
        }else if((is_black_left() == 1) && (is_black_right() == 1)){
        	stop();
        	LED(0);
        	break;
        }

    }

    stop();
    return 0;
}
int main(void)
{
    if(wiringPiSetup() == -1) { //when initialize wiring failed,print messageto screen
        printf("setup wiringPi failed !");
        return 1;
    }

    pinMode(ReedPin, INPUT);
    LED("GREEN");

    while(1) {
        if(0 == digitalRead(ReedPin)) {
            delay(10);
            if(0 == digitalRead(ReedPin)) {
                LED("RED");
                printf("Detected Magnetic Material!\n");
            }
        }
        else if(1 == digitalRead(ReedPin)) {
            delay(10);
            if(1 == digitalRead(ReedPin)) {
                while(!digitalRead(ReedPin));
                LED("GREEN");
            }
        }
    }
    return 0;
}
예제 #3
0
void cyg_hal_start( void )
{
    /* Board specific prestart that's best done in C */
    hal_board_prestart();

    LED( 0xd0 );

#ifdef CYG_HAL_STARTUP_ROM
    /* Copy data from ROM to RAM */
    hal_copy_data();
#endif
                
    LED( 0xd4 );

    /* Zero BSS */
    hal_zero_bss();

    LED( 0xd8 );

    /* Call constructors */
    cyg_hal_invoke_constructors();

    LED( 0xdc );

    /* Board specific late startup that's best done in C */
    hal_board_poststart();

    LED( 0xf8 );

    /* Call cyg_start */
    cyg_start(); /* does not return */
}
예제 #4
0
void running_light (bool btwo_directions)
{
    static uint8_t u8count = 0;
    static bool bfirstrun = true;
    static int8_t u8direction = 1;
    // Fix firstrun bug
    if (bfirstrun)
    {
        LED (apvu16leds_conf[u8count], apvu16leds_ports[u8count], au8leds_offsets[u8count], ON);
        bfirstrun = false;
        return;
    }
    // Turn the last LED off
    LED (apvu16leds_conf[u8count], apvu16leds_ports[u8count], au8leds_offsets[u8count], TOGGLE);
    // Move forward
    u8count += u8direction;
    if (btwo_directions)
    {
        if (u8count == u8leds-1)
            u8direction = -1;
        else if (u8count == 0)
            u8direction = 1;
    }
    else
        u8count %= u8leds;
    // Turn the next LED on
    LED (apvu16leds_conf[u8count], apvu16leds_ports[u8count], au8leds_offsets[u8count], TOGGLE);
}
예제 #5
0
void setup() {
    keypadSetup();

    LED(DDR) = 0xff;
    LED(PORT) = 0xff;

    onKeypadPress(onPress);
}
예제 #6
0
void mainloop(void)
{
  static unsigned char led_cnt = 0, led_state = 1;

  led_cnt++;

  if ((GPS_Data.status & 0xFF) == 0x03)
  {
    LED(0, OFF);
  }
  else
  {
    if (led_cnt == 150)
    {
      LED(0, ON);
    }
    else if (led_cnt == 200)
    {
      led_cnt = 0;
      LED(0, OFF);
    }
  }

  SDK_mainloop();

  HL2LL_write_cycle(); //write data to transmit buffer for immediate transfer to LL processor

  if (GPS_init_status == GPS_NEEDS_CONFIGURATION) //configuration SM of GPS at startup
  {
    GPS_configure();
  }

  if (gpsDataOkTrigger)
  {
    if (GPS_Data.horizontal_accuracy > 12000)
      GPS_Data.status &= ~0x03;
    if (GPS_timeout > 50)//(GPS_Data.status&0xFF)!=0x03)
    {
      if (led_state)
      {
        led_state = 0;
        LED(1, OFF);
      }
      else
      {
        LED(1, ON);
        led_state = 1;
      }
    }
    GPS_timeout = 0;
    if (GPS_init_status == GPS_STARTUP)
      GPS_init_status = GPS_IS_CONFIGURED; //gps config valid, if received correct packet
    HL_Status.latitude = GPS_Data.latitude;
    HL_Status.longitude = GPS_Data.longitude;

  }

}
void panic(int led1, int led2)
{
	for(;;) {
		_delay_ms(100);
		LED(led1);
		_delay_ms(100);
		LED(led2);
	}		
}
예제 #8
0
void run(void)
{
	int i;
	int led;

	for (i=0; i<10 ; i++) {
		LED(1);		// green.
		Wait(1000);
		LED(0);		// off.
	}
}
예제 #9
0
/*************************************************************************
*                             野火嵌入式开发工作室
*
*  函数名称:LED_test
*  功能说明:LED测试函数,用于测试LED库里的函数是否正常
*  参数说明:无
*  函数返回:无
*  修改时间:2012-2-10
*  备    注:
*************************************************************************/
void  LED_test(void)
{
    LED_INIT();
    while(1)
    {
        LED_DELAY_MS(500);
        LED(LED0,LED_ON);
        LED_DELAY_MS(500);
        LED(LED0,LED_OFF);
    }
}
예제 #10
0
void printmatrix(int matriz[][verticalmax][3])
{	
	int i, j;		
	for(j=verticalmax-1; j>=0; j--)
	{
		for(i=0; i<horizontalmax; i++)
		{
			LED(i,j,matriz[i][j][0]);
                        LED(i,j,matriz[i][j][1]);
                        LED(i,j,matriz[i][j][2]);			
		}
	
	}	
	return;
}
예제 #11
0
void stepSM(int dir)   //0 +1
 {
    static int olddir=0;    //um IOport-read zu vermeiden
    LED(1);  
    PORTBbits.RB10    = 0;    
    PORTBbits.RB11    = 0;      

    TRISBbits.TRISB11 = dir;  // dir    
    if (olddir!=dir)
      __delay_us(4); 
    olddir=dir;
    TRISBbits.TRISB10 = 0; // step 
    __delay_us(4);
    LED(0);
    TRISBbits.TRISB10 = 1; // step  
 }
예제 #12
0
int main(void)
{
	const unsigned short MainCycle = 60;
	Init(MainCycle);

	unsigned short bw, ri;

	for(;;)
	{
		bw = ADRead(0);
		ri = ADRead(1);
		if((bw < 500)&&(ri < 500)){
			go(3,l,l,a);
		}
		else if((bw > 500)&&(ri < 500)){
			go(2,r,s,a);
		}
		else if((bw < 500)&&(ri > 500)){
			go(1,s,r,a);
		}
		else{
			break;
		}

	}
	LED(0);
	motor(0,0);

	return 0;
}
예제 #13
0
파일: spi.c 프로젝트: jinshuhuai/nRF24L01
int main(void)
 {	 
	u8 R='b';		
	delay_init(72);	    	 //延时函数初始化	  
	usart1_init();	 	//串口初始化
 	NRF24L01_Init();    	//初始化NRF24L01 
	LED();	  
 	while(NRF24L01_Check());	//检查NRF24L01是否在位.	
	
 	while(1)
	{
		NRF24L01_TX_Mode();
		if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE))
		{
			R =USART_ReceiveData(USART1);
			USART_ClearFlag(USART1, USART_FLAG_TC);		
			USART_SendData(USART1, USART_ReceiveData(USART1));
			USART_ClearFlag(USART1, USART_FLAG_RXNE);				
		}  
		NRF24L01_TxPacket(&R);  	
		if(R=='a')
		GPIO_ResetBits(GPIOE, GPIO_Pin_5); //PE=0,LED亮
		if(R=='b')
		GPIO_SetBits(GPIOE, GPIO_Pin_5); //PE=1,LED灭		
	}
}
예제 #14
0
int main(void) {
	
	WDT_off(); //watchdog erstmal abschalten
	wdt_disable();
	LED_DDR = (1<<LED_PIN); //register setzen
		
	LED(0); //LED auf LOW ziehen --> AN
	delayms(20); //Delayzeit stellt die Impulsdauer und damit den Helligkeitseindruck ein
	LED(1); //LED auf HIGH setzen --> AUS
	wdt_enable(WDTO_2S); //setze den Watchdogtimer auf 2s
	set_sleep_mode(SLEEP_MODE_PWR_DOWN); //PWR_DOWN --> quasi nur wdt kann chip wecken
    sleep_mode(); //in den Tiefschlaf wechseln
	
	while(1);
	return 0;
}
예제 #15
0
파일: Comm.c 프로젝트: NNUMakerSat/Hub
uint8_t master_HandShake(uint8_t sci_x){
	state_x_Send = false;
	state_x_PowerUp = false;
	while (!timeout && !Sci_Ready()){}
	if (!timeout){
		read_SPI (hand_Shake_Send);
		if (g_RXData != hand_Shake_Rec){	// handshake fail
			LED(1,1,1,5,1);	// Handshake fail (BLUE GREEN RED)
			hand_Shake_FAIL[(m + 9)] = g_RXData;
			m++;
			state_x_PowerUp = true;
		}

	}
	if (m > 20)	// Try three times and move on to science board 2 if no handshake
	{
		state_x_Send = true;
		for (o = 9; o < 29; o++){
		write_Buffer(hand_Shake_FAIL[o]);
	}

}
	if (timeout){return 1;}
	else return 0;
}
예제 #16
0
파일: psgrade.c 프로젝트: cloned67/PSGrade
	int 				main									(void)					{
	 state = init;
	 SetupHardware();
 	 LED(~GREEN);
	 //HMACInit(jig_key,20);
	 //switch_port(0);
	 
 	 for (;;) {
  	  USB_USBTask(); // why not in ISR ?
	
      if (expire ==0){    	
 	   switch (state) {
		case start: 		
		      connect_port(5); 
			  state = p5_wait_reset;
			  break;
			  
		case JIG_wait_reset:
 		      switch_port(5);
		      state = p5_wait_enumerate;
              break;

		case JIG_do_answer: 
		      JIG_Task(); 
			  break;

 	    case JIG_responded:
 		     disconnect_port(5);
		     state = p5_wait_disconnect;
			 break; 

		case JIG_wait_disconnect:
		     if (last_port_conn_clear == 5) {
		      state = p5_disconnected;
		      expire = 20;
			 } 
			 break;
		case JIG_disconnected:	 
     		 LED(GREEN);
			 break;
			 
		default:
		  break;
	   } 
	  }		
	 }
	}
예제 #17
0
int main(void)
{
	const unsigned short MainCycle = 60;
	Init(MainCycle);
	int i;

		for(i=0;i<10000;i++){


			forward(EDGE);
			Wait(50);

        if(ADRead(0)>500){
				 left_motor(EDGE);
				 LED(1);
			 }

			 if(ADRead(1)>500){
				 right_motor(EDGE);
				 LED(2);
			 }


			 if((ADRead(1)>500)&&(ADRead(0)>500)){
				 stop();
				 LED(3);
				 for (;;) {

				         kaeru();
				         Wait(3000);


				     }
				 Wait(10000);
			 }



		}





	return 0;
}
예제 #18
0
파일: user.c 프로젝트: dsky7/PIC
void test1(){
    while(1){
    tarVel1=tarVel1+1000;
    LED(1,500);
    delay_ms(1000);
    }

}
예제 #19
0
int main(void)
{
	const unsigned short MainCycle = 60;
	Init(MainCycle);



    int i;
    unsigned short br;
    unsigned short bl;
    for(i=0; i<N; i++){

      br = ADRead(0); //left
      bl = ADRead(1);  //right


      if(bl<200 && br<200){
   	  step();

      }
       if (bl>200 && br<200){
    	   LED(1);
    	   Wait(100);
    	   LED(0);
    	  right();
       }
       if(br>200 && bl<200){
    	  LED(2);
    	  Wait(100);
    	  LED(0);
    	  left();

       }

       else if(br>200 && bl>200){
    	 forward(0,0);
    	 break;
       }


    }

  buzzer();
	return 0;
}
예제 #20
0
void ClearAll() // Clear all accumulators and turn off outputs
{
	uint8 i;
	for(i=0; i<128; i++)
		AccumulatedData[i]=0;
	SampleCount=0;
	ClearFinalData();
	OC_COUNT(OFF);
	LED(OFF);
}
예제 #21
0
int main(void){

	const unsigned short MainCycle = 60;
	Init(MainCycle);

		for( ; ; ) {

		       // step(,);
		        left = ADRead(0);
                right = ADRead(1);

                	if(left>600){
                		LED(2);
                		Wait(200);
                		turn(32760,32760,50);  //	軌道修正 ~ 右 10k,10k ,persist = 100ms
                	}


                	if(right>600){
                		LED(1);
                		Wait(200);
                		turn(-32760,-32760,50);   //軌道修正  ~ 左 -10k, -10k
                	}


                	if(right > 600 && left > 600){
                		break;
                	}


                	else{
                          step(30,0);
                          buzz(0,30,0);
			       	  }

    LED(0);
		     }



		return 0;
}
예제 #22
0
void leds_display_hex (uint8_t u8num)
{
    uint8_t u8count = u8leds-1;
    while (u8num > 0)
    {
        // Turn the LED representing the current bit on if it is set
        LED (apvu16leds_conf[u8count], apvu16leds_ports[u8count], au8leds_offsets[u8count], u8num & 1);
        u8num >>= 1;
        u8count--;
    }
}
예제 #23
0
/* Write LEN bytes to LEDs at position POS, from BUF.
   Returns actual amount written.  */
unsigned write_leds (unsigned pos, const char *buf, unsigned len)
{
	/* We write the actual LED values backwards, because
	   increasing memory addresses reflect LEDs right-to-left. */
	volatile char *led = &LED (LED_NUM_DIGITS - pos - 1);
	/* We invert the value written to the hardware, because 1 = off,
	   and 0 = on.  */
	DO_LED_COPY (char *img, pos, buf, len,
		     *led-- = 0xFF ^ (*img++ = *buf++));
	return len;
}
void lchika(void) {
    uint8_t i;
    for (i = 0; i < 3; i++) {
        cnt[i]++;
        //奇数ならLEDは消灯
        if (cnt[i] % 2 == 1) {
            LED(i, 0);
        } else {//偶数のとき
            if (cnt[i] / 2 <= v[i] / 100) {//LED点滅回数のほうが電流より少ない間LED点灯
                LED(i, 1);
                cntf[i] = 0; //フラグリセット
            } else {//LEDの点滅回数のほうが電流より多くなったときフラグ加算
                cntf[i]++;
                LED(i, 0);
                if (cntf[i] >= 2) {//フラグが2になったら、元に戻る
                    cnt[i] = 0;
                }
            }
        }
    }
}
예제 #25
0
int main(void)
{
	const unsigned short MainCycle = 60;
	Init(MainCycle);

	LED(3);

	int i;
	for(;;)
	{
		if(ADRead(LEFT_EYE)>BLACK){
			if(ADRead(RIGHT_EYE)>BLACK){
				break;
			}
			else{
				LED(2);
				runl();
			}
		}
		else{
			if(ADRead(RIGHT_EYE)>BLACK){
			LED(1);
			runr();
			}
			else{
				LED(3);
				run();
			}
		}


	}

	Mtr_Run_lv(0, 0, 0, 0, 0, 0);


	return 0;

}
예제 #26
0
void main()
{	
	uchar *p;
	p="by Jasper";	
	Init();
	IsReset=0;
	IsReset=eeprom_read(100);
	
	if(!IsReset)										//首次进入输入密码和显示欢迎界面
	{
		Confirm();
		LCD_clear();
		delay_ms(200);
		LCD_write_str(5,0,"welcome");
	
		while(*p)									
		{
			LCD_write_char(i,1,*p);
			p++;
			i++;
			delay_ms(100);
		}
	}
	
													
	LCD_clear();										//正式进入系统
	LCD_write_str(0,0,"1bell2led3motor");				
	LCD_write_str(0,1,"4fix_password");
	
	while(1)
	{
		eeprom_write(100,0);
		if(select=='1')  								//蜂鸣器模式
		{
			LCD_clear();
			LCD_write_str(0,0,"buzz..send * or");
			LCD_write_str(0,1,"shutdown to exit");
			Bell();
		}
		
		if(select=='2')  LED(); 						//led模式
		
		if(select=='3')  Motor();						//电机模式
		
		if(select=='4')  Write_password();				//修改密码模式
		
	}
		
}
예제 #27
0
void panic_mode(void) {
//    RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power
	lcd_printlc_P(1, 1, PSTR("Panic mode          "));
    LEDS_OFF();
    LED(1, 2);
    blinkdelay();
    LED(1, 2);
    LED(2, 2);
    blinkdelay();
    LED(2, 2);
    LED(3, 2);
    blinkdelay();
    LED(3, 2);
    LED(4, 2);
    blinkdelay();
    LED(4, 2);
    LED(5, 2);
    btn_p = (PIN(SW_PACECAR_PORT) & _BV(SW_PACECAR));
     if (old_p != btn_p) {
         // pacecar button changed
         if (btn_p == 0) pacecarbutton();
         old_p = btn_p;
     }
}
예제 #28
0
void test_circuit_parallel()
{
	//circuit 1
	ngac AC("ac1", 0, 5, 1);
	ngresistor R("r1", 370);
	ngled LED("LED1", 7e-3);
	ngground GND;

	ngline L0(AC.p1, GND.p1);
	ngline L1(AC.p2, R.p1);
	ngline L2(R.p2, LED.p1);
	ngline L3(LED.p2, AC.p1);

	schema SCH;
	SCH.AddDevices(&AC, &R, &LED, &GND, 0);
	SCH.AddLines(&L0, &L1, &L2, &L3, 0);

	circuit CIR(&SCH);
	CIR.Tran("20", "1m");

	//circuit 2
	ngac ac("ac1", 0, 5, 1);
	ngresistor r("r1", 370);
	ngled led("led1", 5e-3);
	ngground gnd;

	ngline l0(ac.p1, gnd.p1);
	ngline l1(ac.p2, r.p1);
	ngline l2(r.p2, led.p1);
	ngline l3(led.p2, ac.p1);

	schema sch;
	sch.AddDevices(&ac, &r, &led, &gnd, 0);
	sch.AddLines(&l0, &l1, &l2, &l3, 0);

	circuit cir(&sch);
	cir.Tran("20", "1m");

	do 
	{
		Sleep(200);
	} while (CIR.IsRunning() || cir.IsRunning());
}
예제 #29
0
/***********************************************************
 * AnimationThread
 ***********************************************************/
int32
LEDAnimation::AnimationThread(void* data)
{
	LEDAnimation *anim = (LEDAnimation*)data;
	
	while (anim->fRunning)
	{
		LED(B_NUM_LOCK,true);	
		LED(B_NUM_LOCK,false);
		
		LED(B_CAPS_LOCK,true);	
		LED(B_CAPS_LOCK,false);
		
		LED(B_SCROLL_LOCK,true);	
		LED(B_SCROLL_LOCK,false);
		
		LED(B_CAPS_LOCK,true);	
		LED(B_CAPS_LOCK,false);				
	}
	anim->fThread = -1;
	return 0;
}
예제 #30
0
/**********************************************************
                       MAIN
**********************************************************/
int	main (void) {

  static int vbat1; //battery_voltage (lowpass-filtered)

  init();
  buzzer(OFF);
  LL_write_init();
  PTU_init();
  ADC0triggerSampling(1<<VOLTAGE_1); //activate ADC sampling

  HL_Status.up_time=0;

  LED(1,ON);

  while(1)
  {
      if(mainloop_trigger)
      {
     	if(GPS_timeout<ControllerCyclesPerSecond) GPS_timeout++;
	  	else if(GPS_timeout==ControllerCyclesPerSecond)
	  	{
  	 		GPS_timeout=ControllerCyclesPerSecond+1;
	  		GPS_Data.status=0;
	  		GPS_Data.numSV=0;
	  	}

        //battery monitoring
        ADC0getSamplingResults(0xFF,adcChannelValues);
        vbat1=(vbat1*14+(adcChannelValues[VOLTAGE_1]*9872/579))/15;	//voltage in mV

		HL_Status.battery_voltage_1=vbat1;
        mainloop_cnt++;
		if(!(mainloop_cnt%10)) buzzer_handler(HL_Status.battery_voltage_1);

	    if(mainloop_trigger) mainloop_trigger--;
        mainloop();
      }
  }
  return 0;
}