Exemple #1
0
IoModule::IoModule(QObject *parent)
	: QObject(parent)
	, whichLamp(0)
{
	initIO();
	logic_init_lamp_machinestat();
}
Exemple #2
0
void main(void) {
	/* your definitions here */
	char data = 0xaa;
	char data2 = 0x55;
	char y;
	// init buttons and seven-segment displays
	initIO();
	// init LCD
	initLCD();
	lcd_onOff(1, 0);
	
	/* your code here */
	




	for (;;) {
		for (y = 0; y < 8; y++) {
			printOnLCD(y, 0, 63, data);
		}
		wait(1000000l);
		for (y = 0; y < 8; y++) {
			printOnLCD(y, 0, 63, data2);
		}
		wait(1000000l);
	}
}
Exemple #3
0
//invoke initIO and initTimer1
void Rainbow::init(void)
{
  initIO();
  initTimer1();
  //fill the color buffer with the first perset pic in flash
  fillColorBuffer(presetMatrixColorData[0]);
}
Exemple #4
0
void main(void) {
    initIO();
    initOscillator();
    initTimer();

    while (1) {
        /* Check to see if the timer has counted beyond 32768 */
        if (TMR1H == 0x80) {
            // reset the timer
            TMR1H = 0;
            TMR1L = 0;

            incrementSeconds();
        }

        /* Check for button input */
        // all buttons are active low
        if (TMR0 >= (unsigned) 192) {
            if (oldButtonS == 0 && _button_s == 1) second = 0;
            if (oldButtonM == 0 && _button_m == 1) incrementMinutes();
            if (oldButtonH == 0 && _button_h == 1) incrementHours();

            oldButtonS = _button_s;
            oldButtonM = _button_m;
            oldButtonH = _button_h;
        }

        /* Update display */
        updateDisplay();
    }
}
Exemple #5
0
int main(void)
{
	initIO();
	USART_init();
	sei();

	while(1)
	{
		//callAction();
		/*if(current != last)
		 {
		 USART_sendchar(current);
		 USART_sendchar('\n');

		 last = current;
		 }*/
		//USART_sendchar('\c');
		//USART_sendchar(state);
		while(packetn == 0)
			;

		USART_sendchar(packet[2]);
		current = packet[2];
		callAction();

		packetn = 0;
	}

	return 0;
}
Exemple #6
0
int main(void) {
	initIO();
    sei();
    
    red(0);
    green(0);
    blue(0);
    _delay_ms(3000);
	while (1) {
        for(int i = 0; i < 255; i++){
            red(255-i);
            green(i);
            _delay_ms(0.5);
        }
        for(int k = 255; k >= 0; k--){
            green(k);
            blue(255-k);
            _delay_ms(0.5);
        }
        for(int j = 0; j < 255; j++){
            red(j);
            blue(255-j);
            _delay_ms(0.5);
        }
        
	}
    
	return 0; // never reached
}
void main(void) {
	// set the previous state of the buttons to a non-zero (i.e. non pressed) value
	int prev_left = 1;
	int prev_right = 1;
	int cur_left = BUTTON_LEFT;
	int cur_right = BUTTON_RIGHT;
	decimal number = {0,0};
	
	// init buttons and seven-segment displays
	initIO();
	
	for (;;) {
		// buffer the current left button input to avoid problems
		cur_left = BUTTON_LEFT;
		// check whether the left button is pressed comparing with the previous state
		if (cur_left == 0 && cur_left != prev_left)
			number = dec(number);
		
		// buffer the current right button input to avoid problems
		cur_right = BUTTON_RIGHT;
		// check whether the left button is pressed comparing with the previous state 
		if (cur_right == 0 && cur_right != prev_right)
			number = inc(number);
		
		// store the current state of the buttons for the next iteration
		prev_left = cur_left;
		prev_right = cur_right;
		
		// display the number calculated
		print(number);
		
		// wait once
		wait(10);
	}
}
Exemple #8
0
int main(void){
  initIO();			//Initialize I/O
  initTimer();
  initComparator();	//Initialize the analog comparator
  lcd_init(LCD_DISP_ON);
  /*
  char buff[7];
  itoa(T_CLOCK,buff,10);
  lcd_puts(buff);
  itoa(ERROR_MARGIN,buff,10);
  lcd_puts(buff);
  */
  
 
  while(1) { 
 
    if (bit_flag) { 
      //lcd_puts("0" + last_bit);	//This math turns a single-digit char into it's ASCII equivalent
      if (last_bit != 0x0F) lcd_putc(last_bit);
      //else lcd_puts("0");
      bit_flag = 0;
    }
    
    if (sync_lost) {
      if (sync_lost == 2) lcd_puts("LOST-2T");
      else lcd_puts("LOST-T");
      lcd_gotoxy(0,1);
      char buff[7];
      itoa(timervalue,buff,10);
      lcd_puts(buff);
      while(1) {}
    }
    
  }
}
Exemple #9
0
int main(void) {
	// initialization
	initIO();
	startupSequence();
	startupSequence();
//	_delay_ms(100);
//	TOGGLE_STATUS;
//	_delay_ms(100);
//	TOGGLE_STATUS;
	
	// spin until position received from connected block (or BBB)
	uint8_t addr = waitForVector();
	
	// assign function pointer to use custom data-collector function
	getData_ptr gData = getMyData;
	sendHorizontal_ptr sHoriz = sendRight;
	sendHorizontal_ptr sVert = sendUp;
	
	// assign received vector to i2c initialization
	setup_i2c(addr, gData, sHoriz, sVert, 0, 0);
	
	forwardChain();
	
	STATUS_PORT &= ~_BV(STATUS_LED);
	
	sei();
	
	// continuously poll i2c for commands
	while (loop_i2c()) {
		advanceVector();
//		_delay_ms(200);
//		TOGGLE_STATUS;
	}
	return 0; // never reached
}
Exemple #10
0
void hubInit(void) {
	initIO();
	calculatePeriod();
	hubLUTInit();
	initRows();
	hubOrientation = HUB_ROTATE_0;
	hubSetOrient(hubOrientation);
	clearScreen();
	//fillScreen(COLOR_RGB(255, 255, 255));
	hubTestBmp();
	screenRedraw();
	
	// 100 Hz * 16 Phases
  HUB_TIMER_CLK_ENABLE();
  TIM_ClockConfigTypeDef sClockSourceConfig;

  hubtim.Instance = HUB_TIMER;
  hubtim.Init.Prescaler = HUB_PRESCALER - 1;
  hubtim.Init.CounterMode = TIM_COUNTERMODE_UP;
  hubtim.Init.Period = period0 - 1;
  hubtim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_Base_Init(&hubtim);

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  HAL_TIM_ConfigClockSource(&hubtim, &sClockSourceConfig);

	HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  HAL_NVIC_SetPriority(TIM1_BRK_TIM9_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
	
	HAL_TIM_Base_Start_IT(&hubtim);
	
	// Timer 2 for NOE
	HUB_TIMER2_CLK_ENABLE();

  TIM_OC_InitTypeDef sConfigOC;

  hubtim2.Instance = HUB_TIMER2;
  hubtim2.Init.Prescaler = 0;
  hubtim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  hubtim2.Init.Period = 0xffff;
  hubtim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_Base_Init(&hubtim2);

  HAL_TIM_OC_Init(&hubtim2);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = period2Min;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_OC_ConfigChannel(&hubtim2, &sConfigOC, NOE_TIM_CHANNEL);

	HAL_TIM_PWM_Start(&hubtim2, NOE_TIM_CHANNEL); 

}
void main(void) {
	short mx, my, tmx, tmy, ignoreBtn;
	char stat[14];
	// TODO initialise variables with the riht value
	//mx = -1;
	//my = -1;
	//ignoreBtn = 0;
	
	lcd_init();
	initIO();
	adc_init();
	
	lcd_clear(0);
	drawField();
	
	for (;;) {
		tmx = (short) (2 - adc_getValue(1) / 255.0 * 2 + 0.5);
		tmy = (short) (2 - adc_getValue(2) / 255.0 * 2 + 0.5);
		if (tmy != my || tmx != mx) {
			drawMarker(mx, my, 0);
			if (fields[mx][my] == 1) {
				placePlayerMark(mx, my, 1);
			}
			drawMarker(mx = tmx, my = tmy, 1);
		}
		if (!BUTTON_RIGHT && !ignoreBtn && !fields[mx][my]) {
			ignoreBtn = 1;
			pushes++;
			placePlayerMark(mx, my, player);
			if (checkStatus(mx, my)) {
				lcd_clear(0);
				sprintf(stat, "Player %u won!", player);
				lcd_drawString(27, 4, 0, 4, 0, 0, &stat[0], 1, 1);
				lcd_flush();
				break;
			}
			if (pushes == 9) {
				lcd_clear(0);
				sprintf(stat, "Undecided!");
				lcd_drawString(32, 4, 0, 4, 0, 0, &stat[0], 1, 1);
				lcd_flush();
				break;
			}
			if (player == 1) {
				player = 2;
			}
			else if (player == 2) {
				player = 1;
			}
		} else if (BUTTON_RIGHT && ignoreBtn) {
			ignoreBtn = 0;
		}
	}
}
Exemple #12
0
/**
 * @brief      Inits everything
 */
void init ()
{
	static FILE fd_stdout= FDEV_SETUP_STREAM(serial_putchar, NULL, _FDEV_SETUP_WRITE);
	stdout = &fd_stdout;
	static FILE fd_lcdout= FDEV_SETUP_STREAM(lcd_putchar, NULL, _FDEV_SETUP_WRITE);
	LCD = &fd_lcdout;
	
	inti_send_buf();
	initIO();

	init_lcd();
}
int main(void)
{
 
  initIO();		//Setup LED and Button pins
  timer0_overflow();	//Setup the button debounce timer
  initTimer1_modes();	//Setup the delay timer

  state = sweep;	//Set default state
  initState(state);	//Setup initial state

  while(1) 
  {
    //If interrupt set the timer flag act on that
    if (timer) {
      switch (state)
      {
        case sweep:
          if (direction) tracker <<= 1;
          else tracker >>= 1;

          if ((tracker == 0x01) | (tracker == 0x80)) direction ^= 1;

          ledPort = tracker;
          break;

        case xor:
          toggle_led();
          break;

        case flash:
          toggle_led();
          break;

        case sleep:
          //Arriving here means we just woke up from sleep
          state = sweep; //Reset state machine
          initState(state);
          break;
      }
      timer = 0;
    }

    if( get_key_press( 1<<KEY0 )) {
      timer1_stop();	//Halt the delay timer
      timer = 0;	//Clear delay timer flag
      
      //Increment the state machine
      if (++state > sleep) state = sweep;

      initState(state);
    }
  }
}
Exemple #14
0
int main(void)
{
	initIO();

	while (1)
    {
        if (TCNT1<2000)
        {
            
        }
        
        if ((TCNT1>=2000) && (TCNT1<=5500) && (dataOK == 1))
        {
            //reset channels from high to low
            if (TCNT1>=CH1_out && bit_is_set(PORTB, PIN0)) PORTB &= ~(1<<PIN0);
            if (TCNT1>=CH2_out && bit_is_set(PORTB, PIN1)) PORTB &= ~(1<<PIN1);
            if (TCNT1>=CH3_out && bit_is_set(PORTB, PIN2)) PORTB &= ~(1<<PIN2);
            if (TCNT1>=CH4_out && bit_is_set(PORTB, PIN3)) PORTB &= ~(1<<PIN3);
            if (TCNT1>=CH5_out && bit_is_set(PORTB, PIN4)) PORTB &= ~(1<<PIN4);
            if (TCNT1>=CH6_out && bit_is_set(PORTD, PIN0)) PORTD &= ~(1<<PIN0);
            if (TCNT1>=CH7_out && bit_is_set(PORTD, PIN1)) PORTD &= ~(1<<PIN1);
            if (TCNT1>=CH8_out && bit_is_set(PORTD, PIN2)) PORTD &= ~(1<<PIN2);
            if (TCNT1>=CH9_out && bit_is_set(PORTD, PIN3)) PORTD &= ~(1<<PIN3);
            if (TCNT1>=CH10_out && bit_is_set(PORTD, PIN4)) PORTD &= ~(1<<PIN4);
            if (TCNT1>=CH11_out && bit_is_set(PORTD, PIN5)) PORTD &= ~(1<<PIN5);
            if (TCNT1>=CH12_out && bit_is_set(PORTD, PIN6)) PORTD &= ~(1<<PIN6);
        }
        
        if ((TCNT1>5500) && (TCNT1<35000))
        {
            CH1_out = uniq(rxbuffer[1], rxbuffer[2]);
            CH2_out = uniq(rxbuffer[3], rxbuffer[4]);
            CH3_out = uniq(rxbuffer[5], rxbuffer[6]);
            CH4_out = uniq(rxbuffer[7], rxbuffer[8]);
            CH5_out = uniq(rxbuffer[9], rxbuffer[10]);
            CH6_out = uniq(rxbuffer[11], rxbuffer[12]);
            CH7_out = uniq(rxbuffer[13], rxbuffer[14]);
            CH8_out = uniq(rxbuffer[15], rxbuffer[16]);
            CH9_out = uniq(rxbuffer[17], rxbuffer[18]);
            CH10_out = uniq(rxbuffer[19], rxbuffer[20]);
            CH11_out = uniq(rxbuffer[21], rxbuffer[22]);
            CH12_out = uniq(rxbuffer[23], rxbuffer[24]);
            
            //ready for output
            dataOK = 1;
        }
        
        
	}
	return 0; // never reached
}
Exemple #15
0
int main(void) {
    //Initialize all IO ports
	initIO();
    
    //Enable global interrupts
    sei();
    

	while (1) {
        //Nothing happens in while loop
        //Could add something here to run while waiting for button
	}
	return 0; // never reached
}
Exemple #16
0
/** @brief The main top level init
 *
 * The main init function to be called from main.c before entering the main
 * loop. This function is simply a delegator to the finer grained special
 * purpose init functions.
 *
 * @author Fred Cooke
 */
void init(){
	ATOMIC_START();			/* Disable ALL interrupts while we configure the board ready for use */
	initPLL();				/* Set up the PLL and use it */
	initIO();				/* TODO make this config dependent. Set up all the pins and modules to be in low power harmless states */
	initAllPagedRAM();			/* Copy table and config blocks of data from flash to the paged ram blocks for fast data lookup */
	initAllPagedAddresses();	/* Save the paged memory addresses to variables such that we can access them from another paged block with no warnings */
	initVariables();		/* Initialise the rest of the running variables etc */
	initFlash();			/* TODO, finalise this */
	initECTTimer();			/* TODO move this to inside config in an organised way. Set up the timer module and its various aspects */
	initPITTimer();			/* TODO ditto... */
	initSCIStuff();			/* Setup the sci module(s) that we will use. */
	initConfiguration();	/* TODO Set user/feature/config up here! */
	initInterrupts();		/* still last, reset timers, enable interrupts here TODO move this to inside config in an organised way. Set up the rest of the individual interrupts */
	ATOMIC_END(); /* Re-enable any configured interrupts */
}
Exemple #17
0
int
main (void)
{
 trace_puts (PROJNAME);

 initIO();
 initIRQ();
 initDWT();
 initSPI();

 PCD8544_Init (0x38);

 char buf[25];
 struct time_types tm;
 uint8_t x, y;

 PCD8544_GotoXY (0, 0);
 PCD8544_Puts ("SirVolta's", PCD8544_Pixel_Set, PCD8544_FontSize_5x7);
 PCD8544_GotoXY (0, PCD8544_GetX_Y(PCD8544_Pos_Y) + PCD8544_CHAR5x7_HEIGHT + 1);
 PCD8544_Puts ("Library", PCD8544_Pixel_Set, PCD8544_FontSize_5x7);
 PCD8544_GotoXY (0, PCD8544_GetX_Y(PCD8544_Pos_Y) + (PCD8544_CHAR5x7_HEIGHT * 2) + 1);
 PCD8544HorizontalLine(PCD8544_GetX_Y(PCD8544_Pos_Y) - (PCD8544_CHAR5x7_HEIGHT  / 2));
 PCD8544HorizontalLine(PCD8544_GetX_Y(PCD8544_Pos_Y) + (PCD8544_CHAR5x7_HEIGHT + 3));

 for (uint8_t i = 10; i > 2; i -= 2)
  PCD8544_DrawCircle(65, 10, i, PCD8544_Pixel_Set);
 PCD8544_DrawFilledCircle(65, 10, 2, PCD8544_Pixel_Set);

 PCD8544_Refresh ();

 PCD8544_GetXY(&x, &y);
 while (1)
  {
   GPIO_ToggleBits(LEDPORT, LEDPIN);
   delayMs(1000);

   tm.seconds = (uint32_t)(uptime_ms / 1000);
   secondsToTime(&tm);
   sprintf(buf, "%.2lud%.2luh%.2lum%.2lus\n", tm.days, tm.hours, tm.minutes, tm.seconds);


   //clear line of text, then print it to display
   PCD8544_DrawFilledRectangle(x, y, x + PCD8544_WIDTH, y + PCD8544_CHAR5x7_HEIGHT, PCD8544_Pixel_Clear);
   PCD8544_GotoXY (x, y);
   PCD8544_Puts (buf, PCD8544_Pixel_Set, PCD8544_FontSize_5x7);
   PCD8544_Refresh ();
  }
}
Exemple #18
0
int main(void)
{
    initIO();
    initTimer0();
    initA2D();
    initUART();
    initLCD();

    sei();

    while(1)
    {
        handleEvents();
    }

    return 0;
}
Exemple #19
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;
}
/********************************************************************
* Main-code
*
********************************************************************/
int main(void)
{
  unsigned int adValue = 0;

  static FILE lcd_fd = FDEV_SETUP_STREAM(lcd_putchar, NULL, _FDEV_SETUP_WRITE);
  stdout = &lcd_fd; // set stdout to lcd stream initalized above

  initIO();
  init_adc();
  init_lcd();
  
  while (1)
  { 
    adValue = read_adc();
    printf("Code:%d RAW=%u\rCalc. = %umV\n",decode(adValue),adValue,(unsigned int)(adValue*2560L/1023L)); // print both lines of lcd display
    _delay_ms(100); // waiting for display
  }
}
void main (void){


    initIO();
    pwm_init();
    motor(0,0);
    lcd_init();
    LSA08_Init();
    __delay_ms(100);

    lcd_clr();
    lcd_goto(0);
    lcd_putstr("LSA08");
    lcd_goto(20);
    lcd_putstr("Demo");

    
    while(SW1);
    while(SW1==0);
    lcd_clr();
   
    PID_MENU();

    lcd_clr();
    lcd_goto(0);   
    lcd_putstr("line\nfollow");

    if (junction_mode){

          junction_follow();
    }

    else {
    
        while(1){
           line_follow();
        }
    }





}
Exemple #22
0
void main(void) {
	/* your definitions here */
	int lVal, rVal;
	
	// init buttons and seven-segment displays
	initIO();
	// init A/D converter
	initADC();
	
	/* your code here */
	for (;;) {
		// read AN1...
		lVal = getADCValue(1) * 3 / 85;
		// read AN2...
		rVal = getADCValue(2) * 3 / 85;
		setLeft7Seg(lVal);
		setRight7Seg(rVal);
	}
}
Exemple #23
0
int main()
{
    //SYSTEMConfigPerformance(SYS_FREQ);
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    PORTFbits.RF1 = 0;

    //Function that initializes all of the required I/O
    initIO();

    //Initialize all of the LED pins
    ledinit();
    adcConfigureAutoScan();
    timersInit();
    motorinit();
    PWMinit();
    motorRstop();
    motorLstop();
    leftspeed = 290;
    rightspeed = 300;

    while(PORTDbits.RD3 == 0)
            {}

            for(i = 0; i < 5000000; i++)
            {
            }
    setpwmR(rightspeed);
    setpwmL(leftspeed);
    motorRfwd();
    motorLfwd();

    //turnright();
    //turnleft();
	while (1)
	{}

    return (EXIT_SUCCESS);
}
int main()
{

    USART0_Init(38400);//Initialize USART0 with baud rate of 38400
    USART1_Init(38400);//Initialize USART1 with baud rate of 38400
    initIO();

    _delay_ms(10);
    sei();                     //Enable Gloabal Interrupt

    while(1){

    	readButtonSatus();

    	checkStatus();

    	_delay_ms(10);
    }


    return 0;

}
Exemple #25
0
Fichier : fy.c Projet : AndTH/GCA
/*
 * initialize all before processing
 */
void startup(void) {
  // configure the ports
  initIO();

  waitMS(10);

  // test display
  choice = 41;
  updateDisplay();
  waitMS(1000);

  choice   = MAX_TRACKS/2 +1;
  curtrack = choice;

  initPositions();
  updateDisplay();

  // get the permanent power setting from eeprom
  if( !readByte(ADDR_KEEPPOWER) )
    power = POWER_OFF;

  // signal started up
  confirm(4);
}
Exemple #26
0
void VS10XX::init()
{
  newSPI.begin();
  initIO();
  reset();
}
Exemple #27
0
int main()
{
    //SYSTEMConfigPerformance(SYS_FREQ);
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    PORTFbits.RF1 = 0;

    //Function that initializes all of the required I/O
    initIO();

    //Initialize all of the LED pins
    ledinit();
    adcConfigureAutoScan();
    timer1Init();
    encodersInit();
    motorinit();
    PWMinit();
    motorRstop();
    motorLstop();
    leftspeed = 310;
    rightspeed = 300;

    while(PORTDbits.RD3 == 0)
            {}

            for(i = 0; i < 5000000; i++)
            {
            }
    setpwmR(rightspeed);
    setpwmL(leftspeed);
    motorRfwd();
    motorLfwd();

    //turnright();
    //turnleft();
	while (1)
	{
                if(readpins(0) > 300)   //left
		{
                    setpwmR(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed < 315)
                        leftspeed++;
                    if(rightspeed > 275)
                        rightspeed--;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 600)
                if(readpins(2) > 600) //right
		{
                    setpwmL(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed > 265)
                        leftspeed--;
                    if(rightspeed < 325)
                        rightspeed++;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 900)
                if(readpins(1) > 900) //middle
		{
                    setpwmR(0);
                    setpwmL(0);
                    motorRstop();
                    motorLstop();
                    turnright();

                }
                //for(i = 0; i < 1500; i++){};


	}

    return (EXIT_SUCCESS);
}
/****************************************************************
* Main
****************************************************************/
int main(int argc, char *argv[]){
	
	char PT1[] = "AIN4", PT2[] = "AIN6";
	int PT1_val[20], PT2_val[20], PT_sum[20];
	int min, minPos, pos, PT1_now, PT2_now, i;

	// Set the signal callback for Ctrl-C
	signal(SIGINT, signal_handler);

	initIO();

	pos = 0;

	//Since we don't know the initial position of motor, we'd better let it rotate 2 steps first
	cRotate(&pos);
	cRotate(&pos);

	//Clockwise rotate for a cycle and record the value in different directions
	for(i = 0; i < 20; i++) {
		PT1_val[i] = analogIn(PT1);
		PT2_val[i] = analogIn(PT2);
		printf("PT1:%4d PT2:%4d\n", PT1_val[i], PT2_val[i]);
		cRotate(&pos);
		delay(100);
	}

	for(i = 0; i < 20; i++) {
		PT_sum[i] = PT1_val[i] + PT2_val[i];
	}

	min = 50000;	//Initialize a large number as min to garantee to be replaced later
	//Find the direction with minimum value, which has the strongest light	
	for(i = 0; i < 20; i++)		
		if(PT_sum[i] < min) {
			min = PT_sum[i];
			minPos = i;
		}
	printf("min:%d minPos:%d\n", min, minPos);

	//Counter clockwise rotate to the direction with strongest light
	for(i = 19; i >= 0; i--) {
		ccRotate(&pos);
		delay(100);
		if((i-minPos) == 0) break;
	}

	//Tracking mode. Find the strongest light and rotate to its direction
	while(keepgoing) {
		//Read analog inputs
		PT1_now = analogIn(PT1);
		PT2_now = analogIn(PT2);
		//Set a threshold. If the difference between the phototransistors is too small, we will not rotate	
		if (PT1_now - PT2_now < 150 && PT1_now - PT2_now > -150){
			delay(300);
		}
		//Decide which direction to rotate
		else if (PT1_now > PT2_now){
			cRotate(&pos);
		}		
		else if (PT1_now < PT2_now){
			ccRotate(&pos);
		}
		printf("PT1:%4d PT2:%4d\n", PT1_now, PT2_now);
        delay(500);
	}
	return 0;
}
Exemple #29
0
/**
 * MidiIO Class Constructor
 *
 * This constructor receive input and output port as arguments and set
 * those ports to the class properties.
 *
 * The in and out arguments are human friendly number (starts from 1)
 * while MidiIO numbering starts from 0
 *
 * @param  int 	in 	input port
 * @param  int 	out	output port
 */
MidiIO::MidiIO(int in, int out): inPort(in - 1), outPort(out - 1)
{
	initIO();
}
Exemple #30
0
/**
* MidiIO Class Constructor
*
* This constructor set the default input and output port to 1
*/
MidiIO::MidiIO(): inPort(1), outPort(1)
{
	initIO();
}