Exemple #1
0
int main(void) {
    char ch;
    InitializeMCU();
    CallEvery(blink, 0, 0.25f);

    while(1) {
        Printf("\nRAS Demo for Robotathon 2013\n");
        Printf(" 0=UART Demo\n 1=Motor Demo\n");
        Printf(" 2=Servo Demo\n 3=I2C Line Sensor Demo\n");
        Printf(" 4=IR Sensor Demo\n 5=Encoders Demo\n");
        Printf(" 6=GPIO Demo\n 7=GPIO Line Sensor Demo\n");
        
        Printf(">> ");
        // Read input from User
        ch = Getc();
        Printf("%c", ch);
        Printf("\n");

        switch(ch) {
            case '0':
                Printf("\n UART Demo\n");
                uartDemo();
                break;
            case '1':
                Printf("\nMotor Demo\n");
                initMotors();
                motorDemo();
                break;
            case '2':
                Printf("\nServo Demo\n");
                initServo();
                servoDemo();
                break;
            case '3':
                Printf("\nLine Sensor Demo\n");
                initI2CLineSensor();
                i2cLineSensorDemo();
                break;
            case '4':
                   Printf("\nIR Sensor Demo\n");
                initIRSensor();
                IRSensorDemo();
                break;
            case '5':
                Printf("\nEncoders Demo\n");
                initEncoders();
                encoderDemo();
                break;
            case '6':
                Printf("\nGPIO Demo\n");
                gpioDemo();
                break;
            case '7':
                Printf("\nGPIO Line Sensor Demo\n");
                initGPIOLineSensor();
                gpioLineSensorDemo();
                break;
        }
    }
}
int main(void)
{	
	char ch;	  	 
	LockoutProtection();
	InitializeMCU();
	initUART();																							    
	
	while(1) {	
		UARTprintf("\nROBZ DEMO\n");
		UARTprintf("  0=UART Demo\n  1=Motor Demo\n");
		UARTprintf("  2=Servo Demo\n  3=Line Sensor\n");
		UARTprintf("  4=IR Sensor Demo\n  5=Encoders Demo\n");
		
		UARTprintf(">> ");
		ch = getc();
		putc(ch);
		UARTprintf("\n");

		if (ch == '0') {
			UARTprintf("\nUART Demo\n");
			uartDemo();	 
		}
		else if (ch == '1') {
			UARTprintf("\nMotor Demo\n");
			initMotors();
			motorDemo(); 
		}
		else if (ch == '2') {
			UARTprintf("\nServo Demo\n");
			initServo();
			servoDemo();   
		}
		else if (ch == '3') {			   
			UARTprintf("\nLine Sensor Demo\n");
			initLineSensor();		  
			lineSensorDemo();
		}
		else if (ch == '4') {	   
			UARTprintf("\nIR Sensor Demo\n");
			initIRSensor();
			IRSensorDemo();	 
		}
		else if (ch == '5') {
			UARTprintf("\nEncoders Demo\n");
			initEncoders();
			encoderDemo();
		}
	}
}
Exemple #3
0
int main(void) {

	initIRSensor(); 
	initMotor();
	initGPIOLineSensor();
	initServo();
	SetServo(servo,0);
	stage = 0;
	//while(1){followLine();}
	//while(1){followWall();}
	//SetMotor(leftMotor, 1); SetMotor(rightMotor, 1);
	while(true){
		LineSensorReadArray(gls, line);
		if (stage==0){			//start state
				if(line[0]<0.5&&line[1]<0.5&&line[2]<0.5&&line[3]<0.5&&line[4]<0.5&&line[5]<0.5&&line[6]<0.5&&line[7]<0.5) {
					followWall();
				}else{
					followLine();
				}
		}else if(stage==1){
			//once 90degree turn passed
//				SetMotor(leftMotor, 1);
//				SetMotor(rightMotor, -1);
				
				SetPin(PIN_F2, 1);
				followWall();
				if (wallPresent()) {followWall();}
				else {
					findLine();
				}
				SetPin(PIN_F2, 0);
		}else if (stage==2){
			//once line found again after walled section
			SetPin(PIN_F1, 1);
			if((line[0]<0.5&&line[1]<0.5&&line[2]<0.5&&line[3]<0.5&&line[4]<0.5&&line[5]<0.5&&line[6]<0.5&&line[7]<0.5)||
				(mostDark())) {			//line[0]>0.5&&line[1]>0.5&&line[2]>0.5&&line[3]>0.5&&line[4]>0.5&&line[5]>0.5&&line[6]>0.5&&line[7]>0.5)
				findEnd();
			}else{
				followLine();
			};
			SetPin(PIN_F1, 0);
		}else{//end of course look for flag
			findObject();
			break;
		}
	}
}